On 29/06/2020 15:29, Mikhail V wrote:
Proposal:
Allow standard python escapes inside curly braces in f-strings.
Main point is to make clear visual distinction between text and
escaped chars:
# current syntax:
print ("\nnewline")
print ("\x0aa")
# new syntax:
print (f"{\n}newline")
print (f"{\x0a}a")
What goes inside curly braces inside an f-string is a Python *expression*:
>>> print(f"{2+40}")
42
It would be totally inconsistent to allow an *unquoted* string instead
(with or without escape characters).
Did you mean to write
# new syntax:
print (f"{'\n'}newline")
print (f"{'\x0a'}a")
That in my opinion would make sense (I was surprised when I discovered
it wasn't legal syntax) although personally I probably wouldn't use it
to make a visual distinction as you describe.
But apparently there are difficulties in implementing it.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/JTZJN2XES3622T7EONJIHMDWO3ODVFQL/
Code of Conduct: http://python.org/psf/codeofconduct/