[Python-Dev] *Simpler* string substitutions

Aahz aahz@pythoncraft.com
Thu, 20 Jun 2002 19:00:11 -0400

On Thu, Jun 20, 2002, Gustavo Niemeyer wrote:
> "Serving HTTP on", sa[0], "port", sa[1], "..."

This is where current string handling comes up short.  What's the
correct way to internationalize this string?  What if the person
handling I18N isn't a Python programmer?

I'm sort of caught in the middle here.  I can see that in some ways what
we currently have isn't ideal, but we've already got problems with
strings violating the Only One Way stricture (largely due to immutability
vs. "+" combined with .join() vs. % -- fortunately, the use cases for
.join() and % are different, so people mostly use them appropriately).

It seems to me that fixing the problems with % formatting for newbie
Python programmers just isn't worth the pain.  It also seems to me that
getting better/simpler interpolation support for I18N and similar
templating situations is also a requirement.

I vote for two things:

* String template class for the text module/package that does
more-or-less what PEP 292 suggests.  I think standardizing string
templating would be a Good Thing.  I recommend that only one
interpolation form be supported; if we're following PEP 292, it should 
be ${var}.  This makes it visually easy for translators to find the

* No changes to current string interpolation features unless it's made
compatible with % formatting.

I don't think I can support dropping % formatting even in Python 3.0;
it's not just source code that will have string formats, but also config
files and databases.
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/