Decorator
ast
nomail at com.invalid
Thu Feb 9 02:03:32 EST 2017
Hi
In python courses I read, it is explained that
@decor
def f():
pass
is equivalent to:
def f():
pass
f = decor(f)
But that's not always true. See this code
class Temperature:
def __init__(self):
self.value = 0
# @property
def celsius(self):
return self.value
celsius = property(celsius)
# @celsius.setter
def celsius(self, value): <-- overwrites previous celsius
self.value = value
celsius = celsius.setter(celsius) <-- error here
When you define the setter function named celsius, it overwrites
the previous property object also named celsius ...
and it fails:
celsius = celsius.setter(celsius)
AttributeError: 'function' object has no attribute 'setter'
any comment ?
More information about the Python-list
mailing list