I have a python class A
with attribute instance_b
as follows :
class A(object):
instance_b = 0
def getB(self):
# Do something Fancy here
return self.instance_b
def setB(self, value):
# Do something Fancy here
self.instance_B = value
b = property(getB, setB)
The property()
function allows me to specify a getter and setter. But is there a way I can specify an incrementer and decrementer? Can I specify similar methods for other operations?
More importantly to me, what if instance_b
is a list instead of an integer. Can I set methods that will substitute for ".insert()" and "+=" and "[-1]"?
Or are only getters and setters (and deletes) allowed to be specified..... And I have to use them to do what I need. So adding an element to the list instance_b
would need to look something like this?
a = A()
a.b = a.b + ["my_item"]