Can someone explain why this is behaving how it is:
Why does m.x not behave the same as v.x?
Code:
class TestClass(object):
def __init__(self,x):
if isinstance(x,TestClass):
self.x=x.x
else:
self.x=x
def foo(self,y):
self.x=self.x+y
t=TestClass(5)
t.foo(4)
t.x #returns 9
v=TestClass(t)
v.foo(3)
v.x #returns 12
m=TestClass(t).foo(3)
m.x #Attribute Error: 'NoneType" object has no attribute 'x'
Why does m.x not behave the same as v.x?