difference between __repr__() and __str__()
gerrit at nl.linux.org
gerrit at nl.linux.org
Tue Feb 29 04:26:09 EST 2000
<quote name="Emile van Sebille" date="951755497" email="emile at fenx.com">
> I like that eval(repr(obj)) stay true. On that basis, the repr(obj)
> should create a string such that obj == eval(repr(obj)).
>>> fp = open('/dev/null')
>>> fp
<open file '/dev/null', mode 'r' at 8153908>
>>> eval(repr(fp))
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "<string>", line 1
<open file '/dev/null', mode 'r' at 8153908>
^
SyntaxError: invalid syntax
</quote>
regards,
Gerrit.
--
Comparison Python GUI's: http://www.nl.linux.org/~gerrit/gui.html
Please comment!
More information about the Python-list
mailing list