[issue43227] Backslashes in function arguments in f-string expressions

Thomas Nabelek report at bugs.python.org
Sun Feb 14 19:52:28 EST 2021


New submission from Thomas Nabelek <nabelekt at gmail.com>:

>From https://www.python.org/dev/peps/pep-0498/#escape-sequences:
"Backslashes may not appear inside the expression portions of f-strings"

Is this supposed to be true even for arguments to functions inside of the expression?

my_str = "test\ test\ test"
path = f"{my_str.replace(r'\ ', ' ')}"

gives

my_str = "test\ test\ test"
path = f"{my_str.replace(r'\ ', ' ')}"

SyntaxError: f-string expression part cannot include a backslash

----------
messages: 386978
nosy: nabelekt
priority: normal
severity: normal
status: open
title: Backslashes in function arguments in f-string expressions
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43227>
_______________________________________


More information about the Python-bugs-list mailing list