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

Guido van Rossum guido@python.org
Wed, 19 Jun 2002 21:06:27 -0400

> 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.

That's intentional.  Trying to put an expression parser in the
interpolation code quickly leads to insanity.

> 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.

I think you're simply trying to do too much in one line.  Simple is
better than complex.

--Guido van Rossum (home page: http://www.python.org/~guido/)