You could use:
with open(‘data.txt’, ‘r’) as file:
data = file.read().replace(‘n’, ”)
In Python 3.5 or later, using pathlib you can copy text file contents into a variable and close the file in one line:
from pathlib import Path
txt = Path(‘data.txt’).read_text()
and then you can use str.replace to remove the newlines:
txt = txt.replace(‘n’, ”)