getting a class attribute using a keyword argument
Nick Coghlan
ncoghlan at iinet.net.au
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(...)
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.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list