slicing the end of a string in a list

John Salerno johnjsal at
Fri Mar 3 05:57:16 CET 2006

Paul Rubin wrote:

> The preferred way to remove the newline is more like:
>    for line in open('C:\\switches.txt'):
>      print line.rstrip()

Interesting. So I would say:

[line.rstrip() for line in open('C:\\switches.txt')]

More information about the Python-list mailing list