[Python-Dev] Re: Suggested changes to PEP 215

Ka-Ping Yee ping@lfw.org
Mon, 14 Jan 2002 21:30:47 -0600 (CST)


On Mon, 14 Jan 2002, Ka-Ping Yee wrote:
> Good point.  Perhaps it is better to simply describe a
> transformation using '%s' and '%' instead of 'str' and '+'
> to avoid this potential confusion altogether.

I have just realized, upon careful thought, that it would be better
to make this syntactic transformation the official specification of
the feature, rather than simply an implementation suggestion.

The current specification is incomplete because it does not adequately
handle certain corner cases:

                             (current PEP)
                             \ then $        $ then \    what i want

    >>> x = 'x41'
    >>> print $'\$x'
    ???                      \x41            A           \x41

    >>> print $'\x24x'
    ???                      x41             $x          $x

    >>> y = '41'
    >>> print $'\x$y'        ???             A           SyntaxError
    ???

The issue is whether backslash-interpretation happens first, or
dollar-interpretation happens first.  The current PEP says \ first.

I hope you see why i want the first case *not* to do \x interpretation
and why i want the second case not to do $ interpretation.  (The
programmer shouldn't have to look for \x24 in her code!)  The third
case is a mess and should definitely be a syntax error.

I'll write a new PEP.


-- ?!ng