perl chomp equivalent in python?

Emile van Sebille emile at
Wed Feb 9 21:16:29 EST 2000


Try this:

>>> lines = open(r'c:\config.sys').readlines()

>>> for line in lines:
 print line[:-1]


Emile van Sebille
emile at

a.c.a. serier <a.serier at> wrote in message
news:87snvk$f2i$1 at
> Hello,
> I have the following problem with lines read with readline.
> How to remove the newline at the end?
> Perl has chomp() to do this.
> In this case use split to split up the line, but the last item has a
> newline at the end.
> I tried both split and replace(line, '\n', '') without result.
> Can't find anything in tutorial, lib ref and FAQ.
> Thank in advance,
> Kees
> --

More information about the Python-list mailing list