slicing the end of a string in a list

John Salerno johnjsal at
Fri Mar 3 05:59:17 CET 2006

John Salerno wrote:
> 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')]

That seems to work. And on a related note, it seems to allow me to end 
my file on the last line, instead of having to add a newline character 
at the end of it so it will get sliced properly too.

More information about the Python-list mailing list