[Python-Dev] PEP 292 for Python 2.4

Raymond Hettinger python at rcn.com
Wed Jun 16 08:26:34 EDT 2004

> > For completeness, perhaps update the PEP to specify what will happen
> > with $ strings that do not fall under $$, $indentifier, or
> > ${identifier}.
> Good point, I've pushed out an update.

One other thought, please reconsider the key lookup for ${identifier}.
I think retaining the braces in the key is a mistake.  The purpose of
the braces was to allow trailing characters without intervening
whitespace.  Extending it to have special meaning for SafeDicts was
probably not the way to go.

As a result, the example in the PEP doesn't work anymore:

>>> mapping = dict(name='Guido', country='the Netherlands')
>>> s = dstring('${name} was born in ${country}')
>>> print s % mapping

Traceback (most recent call last):
  File "C:\nondist\sandbox\string\pep292.py", line 124, in -toplevel-
    print s % mapping
  File "C:\nondist\sandbox\string\pep292.py", line 108, in __mod__
    return self._modstr % other
KeyError: '{name}'


P.S.  The PEP example is also missing the rightmost single quotation

More information about the Python-Dev mailing list