[IronPython] __repr__ and __str__ for .NET types
Jonathan Jacobs
korpse-ironpython at kaydash.za.net
Tue May 23 14:57:51 CEST 2006
Hi,
In all the cases I've seen, calling repr on a .NET type ends up calling
ToString which is generally reasonably useful but almost always unnecessarily
verbose. Sometimes it would be nice if it gave you something a little more
specific about the object in question, something less like:
>>> v = Microsoft.DirectX.Vector3()
>>> repr(v)
'X: 0\nY: 0\nZ: 0\n'
and something more like:
>>> class Foo(object): pass
>>> ...
>>> repr(Foo())
'<Foo object at 0x000000000000002B>'
and leaving __str__ to return the ToString value.
This behaviour also fits the CPython documentation
(http://docs.python.org/ref/customization.html), for these two functions, more
closely than the current behaviour, IMO.
Regards
--
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