On Thu, 6 Apr 2006, Michael P. Soulier wrote: [...] > I thought that the distinction was as follows. > > str() should return a human-readable representation of something. > > repr() should return a machine-readable representation of something, suitable > for an exec command. [...]
Is this old chestnut really still around? repr() is for debugging; it does not have to return an eval()-able string. The __repr__ docs explain that well. Perhaps the documentation for repr() is still partly to blame for this confusion. It says: """ Return a string containing a printable representation of an object. This is the same value yielded by conversions (reverse quotes). It is sometimes useful to be able to access this operation as an ordinary function. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(). """ I suggest (for Py3k, anyway): """ Return a string containing a printable representation of an object. This is useful for debugging. Often, this function returns a string of the form "<...some useful description...>". For some types, this function returns a string that would yield an object with the same value when passed to eval(). """ > That still has value, no? I find the 'debug string' / 'human-readable string' distinction valuable. John _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com