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 __
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
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
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 =
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
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