[Tutor] new classes and default attribute
op73418 at mail.telepac.pt
Wed Nov 19 10:41:07 EST 2003
On Wed, 19 Nov 2003 10:24:40 -0500, you wrote:
>That is true for a string, but doesn't work with a number.
> >>> repr(i)
> >>> i.__repr__()
> >>> i
>I did try to look this up, but none of the "magic methods" seemed to apply.
>I do agree that __repr__ comes close.
Well, it's either calling __str__ or __repr__. I never quite know when
Python calls each. Go figure...
The differences between __repr__ and __str__ are indeed subtle and
have already motivated some long threads at comp.lang.py - check them
out if you're interested.
With my best regards,
P.S: At a Python prompt I get the following:
>>> i = 123
>>> print str(i)
>>> print repr(i)
>>> print repr(i) == str(i)
>>> i = "123"
>>> print i
More information about the Tutor