I use the following code segment to read a file in python:
with open (\"data.txt\", \"r\") as myfile:
data=myfile.readlines()
Input fil
I'm surprised nobody mentioned splitlines()
yet.
with open ("data.txt", "r") as myfile:
data = myfile.read().splitlines()
Variable data
is now a list that looks like this when printed:
['LLKKKKKKKKMMMMMMMMNNNNNNNNNNNNN', 'GGGGGGGGGHHHHHHHHHHHHHHHHHHHHEEEEEEEE']
Note there are no newlines (\n
).
At that point, it sounds like you want to print back the lines to console, which you can achieve with a for loop:
for line in data:
print line