I was trying to write some code that would check if an item has some attributes , and to call them . I tried to do that with getattr , but the modifications wouldn’t be permanent . I made a ‘dummy’ class to check upon this . Here is the code I used for the class :
class X: def __init__(self): self.value = 90 def __get(self): return self.value def __set(self,value): self.value = value value = property(__get,__set) x = X() print x.value # this would output 90 getattr(x,'value=',99) # when called from an interactive python interpreter this would output 99 print x.value # this is still 90 ( how could I make this be 99 ? )
Thanks !
You need to do something like
Note that the ‘internal’ variable has to have a different name than the property (I used
_value).Then,
should work.