Dealing with the __str__ method in classes with lots of attributes

Dave Angel d at davea.name
Fri May 11 07:58:18 EDT 2012


On 05/11/2012 07:16 AM, Andreas Tawn wrote:
>> <SNIP>
>> This is a very interesting solution.
>>
>> I think it might be better suited (for my purpose) to __repr__ rather than __str__, mostly because I still lose control of the order the attributes appear.

I have no idea why using __repr__ versus __str__ would make any
difference in the order of the attributes. They're going to come out in
the order you specify, regardless of what you name your method.  If you
don't like the arbitrary order you get from the dictionary, then either
sort it, or provide an explicit list.



-- 

DaveA




More information about the Python-list mailing list