[Python-Dev] Re: Suggested changes to PEP 215
Ka-Ping Yee
ping@lfw.org
Mon, 14 Jan 2002 20:51:43 -0600 (CST)
On Mon, 14 Jan 2002, Jason Orendorff wrote:
> One of the examples in PEP 215 is a bit wrong, I think.
>
> >>> print $'\$a'
> 5
>
> This should output a backslash before the 5, because the
> string '\$a' has a backslash character in it.
You are correct. I'll make this change.
> Also, for clarity, PEP 215 should explicitly specify
> that the substitution only occurs once.
[...]
> Maybe there should also be examples demonstrating that $-strings
> adopt the local namespace.
Sure, that wouldn't hurt. More examples are a good idea.
> Consider:
>
> def f(str):
> # The argument 'str' masks the builtin str() function.
> a, b = find_stuff(str)
> print $'a = $a, b = $b'
> return a, b
>
> It should be specified that $-strings do not use the local
> "str" and "unicode" names to find str() and unicode()
Good point. Perhaps it is better to simply describe a
transformation using '%s' and '%' instead of 'str' and '+'
to avoid this potential confusion altogether.
-- ?!ng