K
K
kibergile2020-07-07 08:44:30
Python
kibergile, 2020-07-07 08:44:30

How to fix EOL error?

Throws an error "SyntaxError: EOL while scanning string literal" when executing the code:

text = ' 0x61 0x73 0x64 '
text = text.replace('0', R'\')
text = text.replace(' ', '')
print(text)


what is the problem? does replace really not want to use "raw" strings?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-07-07
@kibergile

Quote from documentation :

Even in a raw literal, quotes can be escaped with a backslash, but the backslash remains in the result; for example, r"\"" is a valid string literal consisting of two characters: a backslash and a double quote; r"\" is not a valid string literal (even a raw string cannot end in an odd number of backslashes) . Specifically, a raw literal cannot end in a single backslash (since the backslash would escape the following quote character). .

Simply put, a single backslash cannot be a raw string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question