New Python 3.0 string formatting - really necessary?

Scott David Daniels Scott.Daniels at Acm.Org
Fri Dec 19 19:05:42 EST 2008


excord80 wrote:
> On Dec 19, 11:01 am, walterbyrd <walterb... at iname.com> wrote:
>> To me, it seems that this:
>>   print "%s=%d" % ('this',99)
>> Is much easier, ...
>> This (if it's right) is much longer, ...
>> print( "{0}={1}".format('this',99))
> Yeah, I like the old way better too. It's got this nice elegant
> simplicity to it (using the percent sign for not only the things
> inside the string, but also to separate it from the tuple that
> follows). Also, I like having only *one* special symbol (`%') to worry
> about in my strings instead of two (`{' and `}').

Ah, but for internationalization, you can change the format
string to take args in a different order if, for example,
French messages want modifiers on one side and English on the other.
The code can stay the same, while only the text used to do the
formatting must change.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list