Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
IT Security NachrichtenNew infosec products of the week: October 2, 2026(02.10.2026 um 06:00 Uhr)
•
IT Security NachrichtenERP-Migration: Kostenfalle Schnittstellen(02.10.2026 um 05:34 Uhr)
•
Android Tipps & SecurityAmazon reduziert eure Prime-Gebühr jetzt auf den alten Preis(02.10.2026 um 06:00 Uhr)
•••
Sicherheitslücken (CVE)CVE-2026-21140 | Samsung Devices access control (EUVD-2026-91157)(02.10.2026 um 05:08 Uhr)
••••
Sichere ProgrammierungWhat Can NSL Actually Do? — A Look at Nova Signal Language(02.10.2026 um 05:14 Uhr)
•
IT Security NachrichtenNew infosec products of the week: October 2, 2026(02.10.2026 um 06:00 Uhr)
•
IT Security NachrichtenERP-Migration: Kostenfalle Schnittstellen(02.10.2026 um 05:34 Uhr)
•
Android Tipps & SecurityAmazon reduziert eure Prime-Gebühr jetzt auf den alten Preis(02.10.2026 um 06:00 Uhr)
•••
Sicherheitslücken (CVE)CVE-2026-21140 | Samsung Devices access control (EUVD-2026-91157)(02.10.2026 um 05:08 Uhr)
••••
Sichere ProgrammierungWhat Can NSL Actually Do? — A Look at Nova Signal Language(02.10.2026 um 05:14 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

Property Decorators

Fist thing, What is Decorators? In Python, a decorators is a special type of function that modifies or enhances the behaviour of another function or method…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

Fist thing,

What is Decorators?

In Python, a decorators is a special type of function that modifies or enhances the behaviour of another function or method without changing its actual code.



Here is an analogy:-

Imagine you have a gift, let say a book. To make it special you wrap up with gift paper. Just like decorators.



Here is the problem when I change the model name of our car attribute it get change but it shouldn't be happened:-




class Car:
total_car=0
def __init__(self,brand,model):
self.brand=brand
self.model=model
Car.total_car+=1
def full_function(self):
return f"{self.brand} {self.model}"
def fuel_type(self):
return "Petrol or Desiel"

@staticmethod
def general_description():
return "Cars mean of transportation"

class ElectricCar(Car):
def __init__(self,brand,model,battery_size):
super().__init__(brand,model)
self.battery_size=battery_size
def fuel_type(self):
return "Electric Charge"

Tata=Car("TATA","Sedan")
Mahindera=Car("Mahindera","Geep")

Tata.model="city"
print(Tata.model)



Output:
city


As you can see I can change model name how avoid this situation and make model read-only.



We are going to use property method. What property method going to do is that having control over attribute so nobody can have access of it.




class Car:
total_car=0
def __init__(self,brand,model):
self.brand=brand
self.__model=model
Car.total_car+=1
def full_function(self):
return f"{self.brand} {self.__model}"
def fuel_type(self):
return "Petrol or Desiel"

@staticmethod
def general_description():
return "Cars mean of transportation"
@property
def model(self):
return self.__model

class ElectricCar(Car):
def __init__(self,brand,model,battery_size):
super().__init__(brand,model)
self.battery_size=battery_size
def fuel_type(self):
return "Electric Charge"

Tata=Car("TATA","Sedan")
Mahindera=Car("Mahindera","Geep")

Tata.model="city"
print(Tata.model)



Output:
ERROR!
Traceback (most recent call last):
File "", line 26, in
File "", line 5, in __init__
AttributeError: property 'model' of 'Car' object has no setter



  1. You need private the model attribute.

  2. Use property method to have access of an attribute so nobody can modify it.

  3. It also says you cannot even modify with function (model()).

  4. After erasing Tata.model="city" then only you can have access to it.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Property Decorators

Thematisch verwandte Begriffe: Property, Decorators · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag