Making a list-inhereted object return standard repr?
Philip Swartzleonard
starx at pacbell.net
Sat Feb 2 01:21:12 EST 2002
Jason Orendorff || Fri 01 Feb 2002 08:32:57p:
> Philip Swartzleonard wrote:
>> Ok, so i decided to make my container class inherit from list, [...]
>> I want to change __repr__ and __str__ to do something more like the
>> first case again [...]
>
> class Foo(list):
> def __repr__(self):
> basic = object.__repr__(self)
> values = list.__repr__(self)
> return basic[:-1] + ' containing ' + values + '>'
>
> ## Jason Orendorff http://www.jorendorff.com/
Thanks! That's copy-and-paste'ly what i need. I knew it was something more
or less obvious i was missing %D.
(although i may have to leave out the contains, as it gives me things like
<__main__.Cell object at 0x015F0210 containing [<__main__.Player object at
0x015E7870 containing []>]> ... so far every object is a container :)
(Incidentally, my other problem was that i was doing something like 'if
new_container == self: complain', which suddenly turned into a comparasion
between two empty lists instead of two object ids... IS fixed it fine :)
--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com
More information about the Python-list
mailing list