I have a problem with a python program. In this program I have to take strings from a file and save it to a list. The problem is that in this file some strings occupy more lines.
The file named 'ft1.txt' is structured like this:
'''
home
wo
rk
''''
sec
urity
'''
inform
atio
n
'''
Consequently opening the file and doing f.read ()
I get out:
" \n\nhome\nwo\nrk\n\nsec\nurity\n\ninform\nation\nn "
.
I execute the following code:
with open('ft1.txt', 'r') as f: #i open file
list_strin = f.read().split('\n\n') #save string in list
I want output [homework, security, information]
.
But the actual output is [home\nwo\nrk, sec\nurity, inform\nation\nn]
How can I remove the special character "\n"
in individual strings and merge them correctly?