[Tutor] easy newbie questions: text file to list?
Bob Gailer
bgailer@alum.rpi.edu
Mon May 19 22:49:19 2003
At 06:50 PM 5/19/2003 +0000, ashleigh smythe wrote:
>Hello. I have a text file that looks like this:
>
>Y16911
>AF202148
>U81576
>AF202159
>...
>
>I can get Python2.2 on my Linux to read the file with file.read() which
>makes it look like this:
>'Y16911\nAF202148\nU81576\n...'
>
>I would like to turn these items into a list
1) file.readlines(). That will give you a list of lines with \n at the end
of each line.
2) file.read().split('\n'). That will give you a list of lines without \n
at the end.
[snip]
Bob Gailer
bgailer@alum.rpi.edu
303 442 2625