[Python-Dev] cpython (3.2): Issue #14123: Explicitly mention that old style % string formatting has caveats

Nick Coghlan ncoghlan at gmail.com
Sun Feb 26 22:13:11 CET 2012


On Mon, Feb 27, 2012 at 5:23 AM, Eli Bendersky <eliben at gmail.com> wrote:
>
>> It would be nice to call it something else than "printf-style
>> formatting". While it is certainly modelled on printf(), knowledge of C
>> or printf is not required to understand %-style formatting, nor even to
>> appreciate it.
>
>
> +1. The section is already titled "old string formatting operations" so if
> this name is acceptable it should be reused. If it's not, it should then be
> consistently changed everywhere.

I deliberately chose printf-style as being value neutral (whereas
old-style vs new-style carries a heavier recommendation that you
should be using the new one). Sure you don't need to know printf to
understand it, but it needs *some* kind of name, and "printf-style"
acknowledges its roots. Another value-neutral term is "mod-style",
which describes how it is invoked (and I believe we do use that in a
few places already).

I didn't actually expect that paragraph to be incorporated wholesale
into the docs - it was intended as a discussion starter, not a
finished product. Aside from the last two sentences, the other big
problem with it is that print-style formatting *does* support
formatting arbitrary objects, they're just forced to go through type
coercions whereas .format() allows objects to define their own
formatting specifiers (such as datetime with strftime strings).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list