Bruno Desthuilliers
2/14/2008 1:26:00 PM
Christian Heimes a écrit :
> Dennis Lee Bieber wrote:
>> What's wrong with just
>>
>> str(0.3)
>>
>> that's what "print" invokes, whereas the interpreter prompt is using
>>
>> repr(0.3)
>>
>
> No, print invokes the tp_print slot of the float type. Some core types
> have a special handler for print. The tp_print slot is not available
> from Python code and most people don't know about it. :]
???
bruno@bruno:~$ python
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Toto(object):
.... def tp_print(self):
.... return "AHAHAHA"
....
>>> t = Toto()
>>> t
<__main__.Toto object at 0xb7db8d6c>
>>> print t
<__main__.Toto object at 0xb7db8d6c>
>>> (0.3).tp_print
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'float' object has no attribute 'tp_print'
>>> (0.3).__print__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'float' object has no attribute '__print__'
>>> (0.3).__tp_print__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'float' object has no attribute '__tp_print__'
>>>
I Must have miss something...