[Python-Dev] Re: PEP 292, Simpler String Substitutions

Joe Mason joe@notcharles.ca
Wed, 19 Jun 2002 16:37:59 -0500


On Wed, Jun 19, 2002 at 08:52:38AM -0400, Guido van Rossum wrote:
> I imagine that the most common use case is a situation where the dict
> is already prepared.  I think **dict is slower than a positional dict
> argument.  I agree that keyword args would be useful in some cases
> where you can't trust the string.

As Barry noted, this isn't as powerful as PEP 215 (er, was that the
right number?  The earlier $interpolation one, anyway) because it
doesn't allow arbitrary expressions.  I'd imagine a common use case
would be to shortcut an expression without binding it to a local
variable,

  "The length is ${length}".sub(length = len(someString))

In this case it would be handy to use the default environment overridden
by the new bindings, so you could do
  
  "The length of ${someString} is ${length}".sub(length =
    len(someString))

But that could get messy real fast.  The idiom could be

  "The length of ${someString} is ${length}".sub(someString =
    someString, length = len(someString))

But that's ugly.

Joe