[Python-ideas] String interpolation for all literal strings

Chris Angelico rosuav at gmail.com
Thu Aug 6 01:59:57 CEST 2015


On Thu, Aug 6, 2015 at 7:24 AM, Oscar Benjamin
<oscar.j.benjamin at gmail.com> wrote:
> What would be the point? If both are available then I would just
> always use the f-string since I prefer local explicitness over the
> global effect of a __future__ import. Or is there a plan to introduce
> the f-prefix and then deprecate it in the even more distant future
> when all strings behave that way?

If it's done that way, the f-prefix will be like the u-prefix in
Python 3.3+, where it's permitted for compatibility with older
versions, but unnecessary. Future directives are the same - you can
legally put "from __future__ import nested_scopes" into Python 3.6 and
not get an error, even though it's now pure noise. I don't have a
problem with that.

Whether or not it's good for string literals to support interpolation,
though, I'm not sure about. The idea that stuff should get
interpolated into strings fits a shell scripting language perfectly,
but I'm not fully convinced it's a good thing for an applications
language. How shelly is Python? Or, what other non-shell languages
have this kind of feature? PHP does (which is hardly an
advertisement!); I can't think of any others off hand, any pointers?

Side point: My preferred bike shed color is \{...}, despite its
similarity to \N{...}; Unicode entity escapes aren't common, and most
of the names have spaces in them anyway, so there's unlikely to be
real confusion. (You might have a module constant
INFINITY=float("inf"), and then \N{INFINITY} will differ from
\{INFINITY}. That's the most likely confusion I can think of.) But
that's insignificant. All spellings will come out fairly similar in
practice.

ChrisA


More information about the Python-ideas mailing list