Message23133
Logged In: YES
user_id=4771
Re-closing. This is a known documentation bug: all this is
expected, but just under-documented. 'str(x)' issues a
special method call to '__str__' on 'x', but the real
definition of "calling a special method" on an object 'x' is
as follows: look up the name "__str__" in the dict of
type(x), then in the dict of the parent types in MRO order.
It's really not the same thing as an attribute lookup.
The reason for this, to put Michael's argument differently,
is that if 'str(x)' would really work like 'x.__str__()',
then this is what would occur:
>>> class X(object):
... def __repr__(self):
... return "hello"
...
>>> X()
hello
>>> X
TypeError: __repr__() takes exactly 1 argument (0 given)
because X.__repr__() is just an unbound method call with a
missing argument. There is no such thing as "default values
for self" in Python. |
|
| Date |
User |
Action |
Args |
| 2007-08-23 14:27:27 | admin | link | issue1066490 messages |
| 2007-08-23 14:27:27 | admin | create | |
|