Extending Python: rewriting a single method in C

Jacek Generowicz jmg at ecs.soton.ac.uk
Wed Mar 14 06:11:09 EST 2001


duncan at rcp.co.uk (Duncan Booth) writes:

> Jacek Generowicz <jmg at ecs.soton.ac.uk> wrote in 
> <g0g0ggy7ct.fsf at scumbag.ecs.soton.ac.uk>:
> 
> >>>> print a.__getattr__("bar")
> >Traceback (most recent call last):
> >  File "<stdin>", line 1, in ?
> >AttributeError: 'foo' instance has no attribute '__getattr__'
> >
> >
> What you want is:
> >>> print getattr(a, "bar")
> 4

Ha ha ha ha !

Doh!

I definitely tried

   a.__getattr__("bar")
   __getattr__(a,"bar")

AND

   a.getattr("bar")

but not

   getattr(a, "bar").

Thanks.

Jacek



More information about the Python-list mailing list