Referencing vars, methods and classes by name

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Feb 8 11:31:42 EST 2007


On 8 feb, 05:51, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> "Gabriel Genellina" <gagsl... at yahoo.com.ar> writes:
> > >    obj.getattr(a)()
> > > but even that is a bit ugly, depending.
> > Surely you meant to say getattr(obj, a)()
>
> Yeah, darn.  Counterintuitive.  I keep making that error in my own
> code too.  Maybe I should put in an RFE.

The "method" way is using __getattribute__ or __getattr__.
A generic function helps on using it on objects of any kind - like
len()
Perhaps it was more important with old style classes.

--
Gabriel Genellina




More information about the Python-list mailing list