Yet another Python textbook
d at davea.name
Wed Nov 21 23:58:37 CET 2012
On 11/21/2012 05:17 PM, Chris Angelico wrote:
> That said, though, I'm just glad that %-formatting is staying. It's an
> extremely expressive string formatting method, and exists in many
> languages (thanks to C's heritage). Pike's version is insanely
> powerful, Python's is more like C's, but all three are compact and
> str.format(), on the other hand, is flexible. It strikes me as rather
> more complicated than a string formatting function needs to be, but
> that may be a cost of its flexibility.
Some don't realize that one very powerful use for the .format style of
working is that it makes localization much more straightforward. With
the curly brace approach, one can translate the format string into
another language, and if the parameters have to be substituted in
another order, it's all in one place.
Twenty years ago, I implemented such a thing for our product (C++), for
just that reason. I'm sure that by now, the libraries exist somewhere
in the C++ stdlibs, or at least in Boost.
More information about the Python-list