Intercept methods/raise exception
Remco Gerlich
scarblac-spamtrap at pino.selwerd.nl
Thu Jul 20 09:34:45 EDT 2000
Thomas Weholt wrote in comp.lang.python:
> I tried using __getattr__, like
>
> def __getattr__(self, attrname):
> print 'Trace:', attrname
> return getattr(self, attrname)
>
> But it crashed terribly. The object in question is accessed lots of
> times. When I ran it, it printed :
> Trace: __coerce__
> Some hundred, thousands times, then collapsed with a bang.
This is simple infinite recursion. The getattr() call calls __getattr__,
etc.
Try returning self.__dict__[attrname].
--
Remco Gerlich, scarblac at pino.selwerd.nl
Murphy's Rules, "First you take off the lens cap":
Tri-Tac's FTL: 2448 reveals that a ship's sensors have a 1 per cent of
failing to detect a giant gas planet 300 feet away. The chance rises
to 11 per cent if you don't know what you are looking for.
More information about the Python-list
mailing list