3 ms·
In python the default is that things that look like attributes/properties REALLY are direct access. If you later need to shim them out into a function you use t
by TylerE 12y ago
In python the default is that things that look like attributes/properties REALLY are direct access. If you later need to shim them out into a function you use the @property decorator (and foo.setter if you need read/write)
class Blah(object):
foo = 2 # A normal property. Direct access
@property
def bar(self):
return self.some_lookup_method()
@bar.setter
def bar(self, value):
self.set_the_bar(value)
- rch 12y agoThanks for mentioning this. I've found the Python approach works really well in practice.