slicing the end of a string in a list
johnjsal at NOSPAMgmail.com
Fri Mar 3 04:55:34 CET 2006
Ben Cartwright wrote:
> Actually, it creates a new string instance with the \n character
> removed, then discards it. The original switches string hasn't
> Yes. You are repeated assigning a new string instance to "line", which
> is then never referenced again.
Ah, thank you!
> PS - actually, you can accomplish all of the above in a single line of
> print [line[:-1] for line in open('C:\\switches.txt')]
Wow, that just replaced 7 lines of code! So *this* is why Python is
More information about the Python-list