slicing the end of a string in a list
Paul Rubin
http
Mon Mar 6 16:26:48 EST 2006
Steve Holden <steve at holdenweb.com> writes:
> >>>[line.rstrip() for line in open('C:\\switches.txt')]
> > How would I manually close a file that's been opened this way? Or is
> > it not possible in this case? Is it necessary?
>
> In CPython it's not strictly necessary to close the file, but other
> implementations don't guarantee that a file will be closed after the
> last reference is deleted.
>
> So for fullest portability it's better explicitly close the file.
I wonder whether PEP 343 should be extended somehow. Hmm.
[line.rstrip() for line within open('C:\\switches.txt')] # ugh!!
Other ideas?
More information about the Python-list
mailing list