Dealing with the __str__ method in classes with lots of attributes
Andreas Tawn
andreas.tawn at ubisoft.com
Fri May 11 10:32:35 EDT 2012
> 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.
Only that, as the docs say, __repr__ should represent the entire object that could be used to build a new object with the same value. For that task the order of the attributes is immaterial.
I want __str__ to give me something easily readable and ordered in a way that's conveys some meaning about the attributes. It's also helpful to not have to display every attribute, of which there may be dozens.
More information about the Python-list
mailing list