[Python-ideas] Briefer string format
Eric V. Smith
eric at trueblade.com
Thu Jul 23 20:15:55 CEST 2015
On 7/23/2015 1:57 PM, Chris Angelico wrote:
> 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.
Right. This is the "unevaluated f-string" of which I spoke in
https://mail.python.org/pipermail/python-ideas/2015-July/034728.html
It would be a huge code injection opportunity, and I agree it's best we
don't implement it.
Eric.
More information about the Python-ideas
mailing list