Floating point bug?
Jeff Schwab
jeff at schwabcenter.com
Thu Feb 14 12:22:41 EST 2008
Christian Heimes wrote:
> 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. :]
Why does print use the tp_print slot, rather than str()? Are the two
effectively redundant? If (non-repr) string representations are
frequently needed for a given type, could str() be implemented as a
reference to tp_slot, via a C-language extension?
More information about the Python-list
mailing list