Format specification mini-language for list joining

Kwpolska kwpolska at
Sat Nov 10 18:13:47 CET 2012

On Sat, Nov 10, 2012 at 5:51 PM, Paul Rubin < at nospam.invalid> wrote:
> […] Python's format strings are pretty much the same as C's format strings […]

You’re thinking about the old % syntax, 'Hello %s!' % 'world'.  The OP
meant the new str.format syntax ('Hello {}!'.format('world')).

IMO, the idea is useless.  First of, format() exists since 2.6, which
was released in 2008.  So, it would be hard to use it anyways.  Second
of, which is more readable:

    out = 'Temperatures: {0:", ":.1f} Celsius'.format(temps)


    out = 'Temperatures: {} Celsius'.format(', '.join(temps))

101% of the Python community would opt for the second format.  Because
your format is cryptic.  The current thing is already
not-quite-easy-to-understand when you use magic (aligning, type
converting etc.), but your proposition is much worse.  And I hate to
consult the docs while working on something.  As I said, it’s hard to
even get this one changed because str.format is 4 years old.

Kwpolska <>
stop html mail      | always bottom-post |

More information about the Python-list mailing list