list to string
Ben Hutchings
ben.hutchings at roundpoint.com
Tue Feb 27 20:47:33 EST 2001
"Delaney, Timothy" <tdelaney at avaya.com> writes:
<snip>
> It will be much faster and use much less memory. Of course, for this
> particular case, there is a much better method ...
>
> text = string.join(f.readlines(), '\n')
>
> or even
>
> text = f.read() # may have slightly different semantics to the above
> depending on platform, file and open mode
<snip>
f.readlines() leaves the line terminator at the end of each of its
lines, so the first expression will double the line terminators
(except at the end of the last line).
--
Any opinions expressed are my own and not necessarily those of Roundpoint.
More information about the Python-list
mailing list