It seems that in Python, to declare a variable in a class, it is static (keeps its value in the next instances). What better way to get around this problem?
clas
Just leave the declaration out. If you want to provide default values for the variables, initialize them in the __init__
method instead.
class Foo(object):
def __init__(self):
self.number = 0
def set(self):
self.number = 1
>>> foo = Foo()
>>> foo.number
0
>>> foo.set()
>>> foo.number
1
>>> new_foo = Foo()
>>> new_foo.number
0
Edit: replaced last line of the above snippet; it used to read 1
although it was just a typo on my side. Seems like it has caused quite a bit of confusion while I was away.