I want set a pattern observer on my class property
I try to use @classmethod
but it doesn't have setter
property.
class dataframe():
df = None
@classmethod
@property
def weather(cls):
return cls.df
@classmethod
@weather.setter
def weather(cls,value):
cls.df= value
print("the weath was change {}".format(cls.df))
<ipython-input-119-7e26ac08cb26> in dataframe()
6 return cls.df
7 @classmethod
----> 8 @weather.setter
9 def weather(cls,value):
10 cls.df= value
AttributeError: 'classmethod' object has no attribute 'setter'
Then I tried to adapt the solution I found there to my problem Using property() on classmethods
class dataframe_meta(type):
def __init__(cls, *args, **kwargs):
cls.df = None
@property
def change(cls):
return cls.df
@change.setter
def change(cls, value):
cls.df = value
print("the weath was change {}".format(cls.df))
class dataframe(metaclass=dataframe_meta):
pass
dataframe.df = 5
It doesn't return any error but the print
from the function setter was not displayed.
How make it work properly?