[Tutor] Reading from a file

dman dsh8290@rit.edu
Fri, 17 Aug 2001 14:43:00 -0400

On Fri, Aug 17, 2001 at 01:10:24PM -0500, robert frank brenart wrote:
| I'm reading in from a file line by line and splitting up the information
| based on commas... however, the last item in every line has an /012
| attached to it... i.e.
| "CVR",1,2
| comes out as
| ['"CVR"', '7', '3\012']
| Just wondering how I can get rid of that \012.

The \0 part means that that character is being displayed in its octal
format.  012 is '\n' or NL.  What OS created the files and what OS
are you reading them on?  You could strip that character off the
string before you split it.

for line in file.xreadlines() :
    line = line.strip()
    print line.split( "," )