[IronPython] __repr__ and __str__ for .NET types
korpse-ironpython at kaydash.za.net
Tue May 23 05:57:51 PDT 2006
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()
'X: 0\nY: 0\nZ: 0\n'
and something more like:
>>> class Foo(object): pass
'<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.
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 users