Re: defining __repr__

2005-09-15 Thread Gerrit Holl
sven wrote:
 i'd like to define __repr__ in a class to return the standardrepr
 a la __main__.A instance at 0x015B3DA0
 plus additional information.
 how would i have to do that?
 how to get the standardrepr after i've defined __repr__?

 object.__repr__(4)
'int object at 0x94f7d8c'

Gerrit.

-- 
Temperature in Luleå, Norrbotten, Sweden:
| Current temperature   05-09-15 19:19:587.8 degrees Celsius ( 46.0F) |
-- 
Det finns inte dåligt väder, bara dåliga kläder.
-- 
http://mail.python.org/mailman/listinfo/python-list

defining __repr__

2005-09-12 Thread sven
hi list,
i'd like to define __repr__ in a class to return the standardrepr
a la __main__.A instance at 0x015B3DA0
plus additional information.
how would i have to do that?
how to get the standardrepr after i've defined __repr__?

sven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: defining __repr__

2005-09-12 Thread Steve Holden
sven wrote:
 hi list,
 i'd like to define __repr__ in a class to return the standardrepr
 a la __main__.A instance at 0x015B3DA0
 plus additional information.
 how would i have to do that?
 how to get the standardrepr after i've defined __repr__?
 
 sven.
 
It's relatively easy for new-style (type-based) classes:

   class C(object):
  ...   def __repr__(self):
  ... return Extra stuff then\n%s % super(C, self).__repr__()
  ...
   i = C()
   repr(i)
'Extra stuff then\n__main__.C object at 0x4e0b6c'
  

Not immediately clear how to extend that to old-style objects since they 
aren't as cooperative in making their superclass as readily available.

Unless your needs are specifically for old-style classes I'd suggest 
using new-style classes.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

-- 
http://mail.python.org/mailman/listinfo/python-list