P
Pelmen
How can I get rid of recursive call __getattr__ inside this method, if
i need to use method or property of the class?
i need to use method or property of the class?
Sorry, but I don't understand your question. Which recursive calls toPelmen said:How can I get rid of recursive call __getattr__ inside this method, if
i need to use method or property of the class?
Pelmen said:How can I get rid of recursive call __getattr__ inside this method, if
i need to use method or property of the class?
The usual mistake here is to write a __getattr__() implementation thatPelmen said:How can I get rid of recursive call __getattr__ inside this method, if
i need to use method or property of the class?
Pelmen said:__str__
Traceback (most recent call last):
File "<pyshell#23>", line 1, in -toplevel-
print t
TypeError: 'NoneType' object is not callable
what i have to do? define __str__ explicitly?
Peter said:Pelmen wrote:
By seemingly not returning anything your __getattr__() method actually
returns None. Instead you should raise an AttributeError when your
__getattr__() encounters the name of an attribute it doesn't handle.
Let's assume Test.__getattr__() should implement an attribute 'alpha' and
nothing else:
... def __getattr__(self, name):
... print "looking up", name
... if name == "alpha":
... return 42
... print "lookup failed for", name
... raise AttributeError
regards
Pelmen said:def __getattr__(self, attr):
print attr
def foo(x):
print x
__str__
Traceback (most recent call last):
File "<pyshell#23>", line 1, in -toplevel-
print t
TypeError: 'NoneType' object is not callable
what i have to do? define __str__ explicitly?
Steve said:or, rather better IMHO,
raise AttributeError("lookup failed for %s" % name)
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.