I have a text file where I want to replace the character \ by ,. After reading the answer of @Jack Aidley in this SO post:
# Read in the file
with open('file.txt', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('n', '***IT WORKED!!!***')
# Write the file out again
with open('file.txt', 'w') as file:
file.write(filedata)
I could successfully change the content such as simple letter like n into ***IT WORKED!!!***. However, if I replace
filedata.replace('n', '***IT WORKED!!!***')
by
filedata.replace('\', '***IT WORKED!!!***')
I get the syntax error:
SyntaxError: EOL while scanning string literal
How can I replace all the \ by ,?