[wingide-users] stack data view doesn't display the return value of __repr__() for objects

Gigi the.gigi at gmail.com
Thu Aug 11 02:57:23 EDT 2005


Hi,
I defined __repr__() method to one of my classes, but in the stack
data view it still shows the default object representation. The funny
thing is that it works in the debug probe view.
Here is a boiled down version of the code:




Here is the output (as expected str(a) returns the __repr__() result
because no __str__ is defined):

str(a)= <Yeahh, it works!!!>
repr(a)= <Yeahh, it works!!!>

This is the debug probe session (when I break in the debugger after
instantiating a)

>>> a
<Yeahh, it works!!!>
>>> 

This is what I get in the stack data view:

<__main__.A 0xb48d30>

It looks like the stack data view displays its own representation of
objects instead of using __repr__() as it should. According to the
Python docs __repr__ is meant exactly for providing rich debug info:

Here is the quote (note the last line specifically):
"""
__repr__( self) 

Called by the repr() built-in function and by string conversions
(reverse quotes) to compute the ``official'' string representation of
an object. If at all possible, this should look like a valid Python
expression that could be used to recreate an object with the same
value (given an appropriate environment). If this is not possible, a
string of the form "<...some useful description...>" should be
returned. The return value must be a string object. If a class defines
__repr__() but not __str__(), then __repr__() is also used when an
``informal'' string representation of instances of that class is
required.
This is typically used for debugging, so it is important that the
representation is information-rich and unambiguous.
"""

Thanks, Gigi


More information about the wingide-users mailing list