equivelant of Java's toString() method? (not repr)
Roy Smith
roy at panix.com
Tue Feb 1 08:17:33 EST 2005
Alex Hunsley <lard at tardis.ed.ac.molar.uk> wrote:
> I suppose I'm looking for the equivelant of Java's toString() method...
That would be str(), which for the most part, just calls your object's
__str__() method. If your object doesn't have an __str__() method, there's
nothing magic Python can do to invent one.
The difference between repr() and str() is that repr() is supposed to
produce a parsable representation of the object; one which could be parsed
by a Python interpreter to re-generate the original object. On the other
hand, str() is supposed to produce a human-readable string.
More information about the Python-list
mailing list