[Tutor] Help: get/set attributes via string names

pm5 at matilda.fiorile.org pm5 at matilda.fiorile.org
Wed Jan 21 05:51:32 EST 2004


On Wed, Jan 21, 2004 at 11:49:48AM +0100, Kalle Svensson wrote:
> [pm5 at matilda.fiorile.org]
> > As far as I can tell, there are various way to [1]customize an
> > attribute for an object.  Consequetly an attribute may be
> > well-defined even if the name is not in ob.__dict__.  So given a
> > string name, how do I access the attribute correctly, if I don't
> > know the way it is defined?
> 
> Use the built-in functions getattr and setattr.

Thanks.  I should have try this first....

> 
> Peace,
>   Kalle
> -- 
> Kalle Svensson, http://www.juckapan.org/~kalle/
> Student, root and saint in the Church of Emacs.
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list