getting a class attribute using a keyword argument

Nick Coghlan ncoghlan at
Mon Jan 17 06:18:15 EST 2005

Guy Robinson wrote:
> Hello,
> I have a list of class instances. I wish to get the appropriate class 
> attribute in each class instance depending on a SINGLE keyword in the 
> calling class.

Py> help(getattr)
Help on built-in function getattr in module __builtin__:

     getattr(object, name[, default]) -> value

     Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.
     When a default argument is given, it is returned when the attribute doesn't
     exist; without it, an exception is raised in that case.


Nick Coghlan   |   ncoghlan at   |   Brisbane, Australia

More information about the Python-list mailing list