I am trying to format text in a .txt file. The content is also in an xml, but I copied to a text file and I am trying to for it. It is currently set up like:
Pufferfish Ocean
Anchovy Ocean
Tuna Ocean
Sardine Ocean
Bream River
Largemouth_Bass Mountain_Lake
Smallmouth_Bass River
Rainbow_Trout River
I am trying to figure out how to open the file and for each line convert it to:
('Pufferfish', 'Ocean')
Is there a way to do this?
This is what I am trying so far, which I know is wrong, and I am trying to look up the correct syntax and way change 'str':
f1 = open('fish.txt', 'r')
f2 = open('fish.txt.tmp', 'w')
for line in f1:
f2.write(line.replace(' ', ','))
for word in line:
f2.write(word.append('(', [0]))
f2.write(word.append(')', (len(word))))
f1.close()
f2.close()