Emily Fortuna wrote:
> Hello all,
> I am writing a function in which (in its simplified form) I am trying to
> return a list of a specified attribute, given a list of objects. It is
> best if I write some hypothetical code to explain:
> class foo:
> def __init__(self, name, data):
>
Did you considered getattr?
> def getAttrs(fooObjs, attr):
> return map(lambda item: getattr(item, attr), fooObjs)
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Hello all,
I am writing a function in which (in its simplified form) I am trying to
return a list of a specified attribute, given a list of objects. It is
best if I write some hypothetical code to explain:
class foo:
def __init__(self, name, data):
self.name = name