RE: how to control formatting of a namedtuple in a list

2016-11-17 Thread Boylan, Ross
Actually, >> print(list(foo, bar)) Traceback (most recent call last): File "", line 1, in TypeError: list()

Re: how to control formatting of a namedtuple in a list

2016-11-17 Thread Ethan Furman
On 11/17/2016 04:09 PM, MRAB wrote: On 2016-11-17 23:49, Boylan, Ross wrote: Thank you; I can confirm that overriding __repr__ makes the list display as I wanted. The decision to use repr inside the list seems very odd, given the context, namely formatting something for display or looking

Re: how to control formatting of a namedtuple in a list

2016-11-17 Thread Ned Batchelder
On Thursday, November 17, 2016 at 6:50:07 PM UTC-5, Boylan, Ross wrote: > Thank you; I can confirm that overriding __repr__ makes the list display as I > wanted. > > The decision to use repr inside the list seems very odd, given the context, > namely formatting something for display or looking

Re: how to control formatting of a namedtuple in a list

2016-11-17 Thread MRAB
On 2016-11-17 23:49, Boylan, Ross wrote: Thank you; I can confirm that overriding __repr__ makes the list display as I wanted. The decision to use repr inside the list seems very odd, given the context, namely formatting something for display or looking for a simple string representation.

RE: how to control formatting of a namedtuple in a list

2016-11-17 Thread Boylan, Ross
Thank you; I can confirm that overriding __repr__ makes the list display as I wanted. The decision to use repr inside the list seems very odd, given the context, namely formatting something for display or looking for a simple string representation. It seems more natural to me to use str or,

Re: how to control formatting of a namedtuple in a list

2016-11-17 Thread Chris Angelico
On Fri, Nov 18, 2016 at 10:04 AM, Boylan, Ross wrote: > Even after defining custom __str__ and __format__ methods they don't affect > the display of objects when they are in a list. Is there a way to change > that, other than explicitly converting each list element to a

how to control formatting of a namedtuple in a list

2016-11-17 Thread Boylan, Ross
Even after defining custom __str__ and __format__ methods they don't affect the display of objects when they are in a list. Is there a way to change that, other than explicitly converting each list element to a string? The last line of output below shows that when I format the list I get