[Python-Dev] transitioning from % to {} formatting

Bugbee, Larry larry.bugbee at boeing.com
Sat Oct 3 08:08:10 CEST 2009


> > Do the users get any say in this?
> 
> I'm a user! :-)
> 
> I hate calling methods on string literals, I think it looks very odd
> to have code like this:
> 
>   "Displaying {0} of {1} revisions".format(x, y)

Ugh!  Good point.  

Is Python to be an easy-to-learn-and-remember language?  I submit we are losing that one.  To a user, this will be confusing.  To a C programmer coming over to Python, especially so.  Some of what makes %-formatting easy to remember is its parallel in C.  

I'm conflicted.  Philosophically I like the idea of mnemonic names over positional variables and allowing variable values determined elsewhere to be inserted in print strings.  It is appealing.  

Unless the benefit is at least 2x, a change should not be made, and I don't think this benefit rises to where it is worth the confusion and problems.  ...and converting the legacy base.  And forget pretty, not that %-formatting is pretty either.  Besides, according to the bench, it is slower too.  And it will take editors a while before the new syntax is supported and colorized, thus some errors for a while.  

...and if one wants a "{" or a "}" in the printed output, one has to escape it?  That is -2x over wanting a "%" in the output.  

So until I see a *significant* benefit, my vote is *not* remove %-formatting.  Make both available and if {} is to win, it will.  



More information about the Python-Dev mailing list