[Python-Dev] converting the stdlib to str.format

Georg Brandl g.brandl at gmx.net
Fri Jun 6 13:08:25 CEST 2008

Greg Ewing schrieb:
> Nick Coghlan wrote:
>> Maybe we should ditch support for 
>> positional arguments and just accept a single dictionary as the sole 
>> parameter to format().
>> "{num} occurs {num} times in this format string".format(dict(num=2))
> If named arguments were to become mandatory, I'd want
> to be able to write that as
>    "...{num}...".format(num = 2)

You already are -- in fact, that is the only way this works.
(I'd wondered why nobody brought this error up in this discussion
before. Probably it wouldn't have been ugly enough.)

I don't see a significant speed difference between positional and keyword
arguments to format() when testing with two arguments.


Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.

More information about the Python-Dev mailing list