[IronPython] __repr__ and __str__ for .NET types

Jonathan Jacobs korpse-ironpython at kaydash.za.net
Tue May 23 20:58:13 CEST 2006


Nicholas Bastin wrote:
> No, actually it doesn't.  The string returned by __repr__ should be  
> able to be used to re-create the object, if that is possible.  In  
> this case,  'X: 0\nY: 0\nZ: 0\n' is a *lot* closer to re-creating the  
> object than  '<Foo object at 0x000000000000002B>' is.  The second  
> case is what gets returned when it isn't possible to re-create the  
> object, but that obviously isn't the case in the example of  
> DirectX.Vector3.

Well, according to the documentation it should look like a valid Python 
expression (which "X: 0\nY: 0\nZ: 0\n" does not) and if that isn't possible 
then it should be in the form of "<...useful information...>". I did get them 
the wrong way around though, __repr__ is supposed to be information-rich 
whereas __str__ is supposed to be concise / convenient.

The reason this bugs me is that trying to debug something that has a 2-page 
ToString() output gets really messy.

-- 
Jonathan

When you meet a master swordsman,
show him your sword.
When you meet a man who is not a poet,
do not show him your poem.
                 -- Rinzai, ninth century Zen master



More information about the Ironpython-users mailing list