0

I'm trying to pass a multi line command into the command line, the problem is that that requires using \ in the command, which is also the line continuation character in python. This results in the line breaks in the string to simply be ignored.

A = """line 1 \
line 2 \
line 3"""

print(A)

Returns:
line 1 line 2 line 3

Wanted return:
line 1 \
line 2 \
line 3

Is there a way to do this still?

NFTLevi
  • 43
  • 1
  • 5

1 Answers1

0

Try adding more slashes:

>>> A = """line 1 \\
line 2 \\
line 3"""
>>> print(A)
line 1 \
line 2 \
line 3
>>>

Or escape it with r"":

>>> A = r"""line 1 \
line 2 \
line 3"""
>>> print(A)
line 1 \
line 2 \
line 3
>>> 

r means the string is a raw string. So the text in it will be escaped.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114