Re: Get list of attributes from list of objects?

2017-08-02 Thread Ian Kelly
On Wed, Aug 2, 2017 at 11:49 AM, Chris Angelico wrote: > On Thu, Aug 3, 2017 at 3:21 AM, Ian Pilcher wrote: >> Given a list of objects that all have a particular attribute, is there >> a simple way to get a list of those attributes? >> >> In other words: >> >> class Foo(object): >> def __

Re: Get list of attributes from list of objects?

2017-08-02 Thread Ian Pilcher
On 08/02/2017 12:49 PM, Chris Angelico wrote: On Thu, Aug 3, 2017 at 3:21 AM, Ian Pilcher wrote: You can't eliminate the loop, but you can compact it into a single logical operation: namelist = [foo.name for foo in foolist] That's a "list comprehension", and is an elegant way to process a list

Re: Get list of attributes from list of objects?

2017-08-02 Thread Terry Reedy
On 8/2/2017 1:21 PM, Ian Pilcher wrote: Given a list of objects that all have a particular attribute, is there a simple way to get a list of those attributes? In other words: class Foo(object): def __init__(self, name): self.name = name foolist = [ Foo('a'), Foo('b'), F

Re: Get list of attributes from list of objects?

2017-08-02 Thread Chris Angelico
On Thu, Aug 3, 2017 at 3:21 AM, Ian Pilcher wrote: > Given a list of objects that all have a particular attribute, is there > a simple way to get a list of those attributes? > > In other words: > > class Foo(object): > def __init__(self, name): > self.name = name > > foolist =

Get list of attributes from list of objects?

2017-08-02 Thread Ian Pilcher
Given a list of objects that all have a particular attribute, is there a simple way to get a list of those attributes? In other words: class Foo(object): def __init__(self, name): self.name = name foolist = [ Foo('a'), Foo('b'), Foo('c') ] namelist = [] for foo in fooli

list of attributes

2008-03-07 Thread Ken
I have a class with a __getattr__ method that returns various methods. I also have the ability to determine the list of method names that are supported by my __getattr__ method (this list would be dynamically generated as it depends on the current state). What I would like to know is if there