Get rid of recursive call __getattr__
bruno at modulix
onurb at xiludom.gro
Wed Dec 14 08:09:45 EST 2005
Pelmen wrote:
> How can I get rid of recursive call __getattr__ inside this method, if
> i need to use method or property of the class?
>
Sorry, but I don't understand your question. Which recursive calls to
__getattr__ ? __getattr__ is only called if a/ it's defined and b/ the
attribute has not been found (see below).
Have you overriden __setattr__ or __getattribute__ ? If yes, please read
the corresponding sections of the Fine Manual.
>>> class Toto(object):
... def __init__(self, name):
... self.name = name
... def __getattr__(self, attname):
... print "__getattr__ called for %s" % attname
... return "%s doesn't exists" % attname
...
>>> t = Toto('toto')
>>> t.name = name
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'name' is not defined
>>> t.name
'toto'
>>> t.age
__getattr__ called for age
"age doesn't exists"
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list