Defining __setattr__
overrides all setter methods / properties I define in a class. I want to use the defined setter methods in the property, if a property exists for a field and use self.__dict__[name] = value
otherwise.
Help! I found one solution that used __setitem__
, but this does not work for me
Where are properties stored in a python class? How do I access them?
How do I define __setattr__
so that it uses the properties for fields with setter methods defined?
class test(object):
def _get_gx(self):
print "get!"
return self.__dict__['gx']
def _set_gx(self, gx):
print "set!"
self.__dict__['gx'] = gx
gx = property(_get_gx, _set_gx)
def __setattr__(self, name, value):
self.__dict__[name] = value
def __init__(self):
pass
also,
Why is "get!" printed twice when I do,
x = test()
x.gx = 4
x.gx
prints:
"gets!"
"gets!"
4