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

Guido van Rossum guido@python.org
Wed, 19 Jun 2002 22:30:59 -0400


> For one, I do not like seeing `$' as a string prefix in Python, and
> wonder if we could not merely go with `%' as we always did in
> Python.  At least, it keeps a kind of clear cut distance between
> Python and Perl. :-)

The $ means "substitution" in so many languages besides Perl that I
wonder where you've been.

> >     In addition, the rules for what can follow a % sign are fairly
> >     complex, while the usual application rarely needs such complexity.
> 
> This premise seems exaggerated to me.  `%' as it stands is not that
> complex to understand.  Moreover, many of us use `%' formatting a lot,
> so it is not so rare that the current `%' specification is useful.

I quite like the positional % substitution.  I think %(...)s was a
mistake -- what we really wanted was ${...}.

> >     1. $$ is an escape; it is replaced with a single $
> 
> Let's suppose we stick with `%', the above rule reduces to something
> already known.
> 
> >     3. ${identifier} [...]
> 
> We could use %{identifier} as meaning `%(identifier)s'.  Clean.  Simple.

Confusing.  The visual difference between () and {} is too small.

> >     2. $identifier [...]
> 
> This is where the difficulty lies.  Since the PEP already suggests that
> ${identifier} was to be preferred over $identifier, why not just go a bit
> forward, and drop 2. altogether?  Or else, how do you justify that using
> it really make things more legible?

Less clutter.  Compare

    "My name is $name, I live in $country"

to

    "My name is ${name}, I live in ${country}"

The {} add nothing but noise.  We're copying this from the shell.

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