You should use new-style class. And the name of the setter should be x
, not set_x
.
class vec(object): # <-----
def __init__(self,v=(0,0,0,0)):
self.v = list(v)
@property
def x(self):
return self.v[0]
@x.setter
def x(self, val): # <--------
self.v[0] = val
According to property
documentation:
Return a property attribute for new-style classes (classes that derive from object).
If you don't use new-style class, a.x = ...
creates a new attribute x
instead of calling the setter.