Format specification mini-language for list joining

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


On Sat, Nov 10, 2012 at 5:51 PM, Paul Rubin <no.email 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)

or

    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 <http://kwpolska.tk>
stop html mail      | always bottom-post
www.asciiribbon.org | www.netmeister.org/news/learn2quote.html
GPG KEY: 5EAAEA16


More information about the Python-list mailing list