Is line concatenation unsupported f-lines?

Is the following syntax unsupported f-lines in Python 3.6? If the string I appends to my f-string, the replacement does not happen:

SUB_MSG = "This is the original message."

MAIN_MSG = f"This longer message is intended to contain " \
             "the sub-message here: {SUB_MSG}"

print(MAIN_MSG)

returns:

This longer message is intended to contain the sub-message here: {SUB_MSG}

If I remove the join line:

SUB_MSG = "This is the original message."

MAIN_MSG = f"This longer message is intended to contain the sub-message here: {SUB_MSG}"

print(MAIN_MSG)

works as expected:

This longer message is intended to contain the sub-message here: This is the original message.

In PEP 498 , the backslash inside the f-string is clearly not supported:

Time sequences

Backslashes may not appear inside parts of an f-string expression, so you cannot use them, for example, to avoid quotes inside f-lines:

>>> f'{\'quoted string\'}'

Are linear joins considered "inside the f-string expression part" and thus are not supported?

+4
source share
2

f -strings, , :

SUB_MSG = "This is the original message."

MAIN_MSG = f"test " \
           f"{SUB_MSG}"

print(MAIN_MSG)

, f-, :

MAIN_MSG = "test " \
           f"{SUB_MSG}"

, , f-:

a = r"\n" \
     "\n"
a   # '\\n\n'   <- only the first one was interpreted as raw string

a = b"\n" \
     "\n"   
# SyntaxError: cannot mix bytes and nonbytes literals
+6

( "f" ):

SUB_MSG = "This is the original message."

MAIN_MSG = f"This longer message is intended to contain " \
         f"the sub-message here: {SUB_MSG}"


print(MAIN_MSG)
+2

Source: https://habr.com/ru/post/1688106/


All Articles