this is my code:
class fun:
def __getattr__(self,key):
return self[key]
def __setattr__(self,key,value):
self[key] = value+1
a = fun()
a['x']=1
print a['x']
and the error is :
AttributeError: fun instance has no attribute '__getitem__'
when i change it to :
class fun:
def __getattr__(self,key):
return self.key
def __setattr__(self,key,value):
self.key = value+1
a = fun()
a.x=1
print a.x
the error is :
RuntimeError: maximum recursion depth exceeded
what can I do, I want get 2