cut off \n

Tom llafba at gmx.net
Mon Jun 9 11:50:37 EDT 2003


Hi,

I have to read data from a file to a list. Unfortunately most of the 
data that I read into my little list ends with a linefeed \n.
Right now I get rid of this by just cutting off the last character. (a = 
l[:-1]).
My problem is that sometimes the last line of the file has a \n and 
sometimes not. With the method above I sometimes cut off parts of my 
string. So it would be much nicer if I can find out if the data does 
have a \n and then cut it off.

This is probably a very common problem but I am pretty new to Phython 
and could find anything useful with google. :-(

Thanks, Tom





More information about the Python-list mailing list