read lines without the line break character at the end?

Andrew Dalke adalke at mindspring.com
Sat Sep 4 17:07:30 EDT 2004


Stan Cook wrote:

> try for line in fp:
>     whatever line[:-1] etc etc
> 
> Whatever you're doing with the line, the new line character will be gone.

Except that 1) you should open the file in "U"niversal
mode, and 2) this will chop the last character from the
last line in the file if the file doesn't end with
a newline.

				Andrew
				dalke at dalkescientific.com




More information about the Python-list mailing list