[Python-ideas] Briefer string format
Chris Angelico
rosuav at gmail.com
Thu Jul 23 19:57:58 CEST 2015
On Fri, Jul 24, 2015 at 3:52 AM, Ron Adam <ron3200 at gmail.com> wrote:
> The part that bothers me is it seems like the "f" should be a unary operator
> rather than a string prefix.
>
> As a prefix:
>
> s = f'{spam}{{eggs}}' # spam
> s2 = s.format(eggs=eggs) # eggs
>
>
> As an unary operator:
>
> s = ? '{spam}{{eggs}}' # spam
> s2 = ? s # eggs
>
> (? == some to be determined symbol)
>
> They are just normal strings in the second case.
Except that they can't be normal strings, because the compiler has to
parse them. They're expressions. You can't take input from a user and
f-string it (short of using exec/eval, of course); it has to be there
in the source code.
ChrisA
More information about the Python-ideas
mailing list