[Tutor] Help: get/set attributes via string names
kalle at lysator.liu.se
Wed Jan 21 05:49:48 EST 2004
[pm5 at matilda.fiorile.org]
> As far as I can tell, there are various way to 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.
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
More information about the Tutor