print a vs print '%s' % a vs print '%f' a

David Cournapeau cournape at gmail.com
Tue Dec 30 04:35:45 CET 2008


On Tue, Dec 30, 2008 at 12:23 PM, James Mills
<prologic at shortcircuit.net.au> wrote:
> On Tue, Dec 30, 2008 at 1:19 PM, David Cournapeau <cournape at gmail.com> wrote:
> (... snip ...)
>
>> print '%f' % a # -> print '1.#INF'
>
> Would this not be controlled by:
> 1. float(a) or a.__float__()
> 2. tp_print

Bah, I made a mistake in my example: complex('inf') should read
float('inf') (complex('inf') does not work). So 1 is out :)

If I read correctly the code, tp_print also calls the format_float
function (as tp_str, and tp_repr), so it looks like it is not used in
that case.

cheers,

David



More information about the Python-list mailing list