[reportlab-users] Many __repr__() methods are really __str__ methods

Andy Robinson reportlab-users@reportlab.com
Thu, 13 Feb 2003 13:20:51 -0000


> >__str(self) methods.   __repr__(self) methods should output a 
> string that Python
> >can interpret and these only output strings which a human can 
> interpret and
> >Python crashes on their output with syntax errors.

You are probably right about what we 'should have done'
but we already did it :-)

Are you asking for all classes in our framework
to be perfectly reproducible through a repr-and-eval
round trip?

I think Guido ruled on this on Python-dev a while
ago.  This would be a big burden on
authors everywhere and would lead to handling
gazillions of keyword arguments in the __init__
method of every class.  I understand it's more
of a 'guideline'. The simplest Python instances
produce illegal syntax 'out of the box' anyway..

>>> class Spam:
... 	pass
... 
>>> sp = Spam()
>>> repr(sp)
'<__main__.Spam instance at 0x011C7740>'
>>> 

Can you be more detailed about what you want to do?
I'd contemplate a global change now if (a) there was a good
reason likely to be useful to several people, (b)
it won't break any real world apps. Otherwise it's
a good guideline to have for "ReportLab 2.0" where
we can break old code...

- Andy