I don't know if I'm missing something extremely obvious, but i found this behaviour to be surprising.
EDIT: Ok so here is an example where i do not use any default arguments - unlike linked duplicate - and it still behaves that way. Can someone please explain why?
class Manager(object):
@classmethod
def calculatesomething(cls, array, attr):
array.append(attr)
return 1
class MyClass(object):
def __init__(self, array):
self.array = array
def __getattr__(self, attr):
variable = Manager.calculatesomething(self.array, attr)
return variable
a = MyClass(['one', 'two', 'three'])
print a.array
print a.four
print a.array
Output:
['one', 'two', 'three']
1
['one', 'two', 'three', 'four']
What i expected:
['one', 'two', 'three']
1
['one', 'two', 'three']
Just like when we have a simple function:
def f(a):
a += 1
return a
a = 1
print a
print f(a)
print a
I expect:
1
2
1
and that's exactly what i get.