I was trying to write some code that will check some attributes in one item, and call them . I tried to do it with Getattr, but modifications would not be permanent. I have created a "dummy" class to check on this here is the code that I used for 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 output is 90 getattr (x, "value =", 99) # When the phone is called from an interactive dragon interpreter output 99 print x.value # It is still 90 (I have it 99 How to make Awareness I?)
Thank you!
you have to do something
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)
Note that one of the "internal" variables must have a different property (I used the _value
.).
Setter (x, 'value', 99)
should work.
Comments
Post a Comment