Is there a better/simpler way to filter blank lines?
Ben Finney
bignose+hates-spam at benfinney.id.au
Tue Nov 4 18:19:02 EST 2008
Larry Bates <larry.bates at vitalEsafe.com> writes:
> bearophileHUGS at lycos.com wrote:
> > xlines = (line for line in open(filename) if line.strip())
>
> Of if you want to filter/loop at the same time, or if you don't want
> all the lines in memory at the same time
The above implementation creates a generator; so it, too, won't need
to load all the lines in memory at the same time
--
\ “Program testing can be a very effective way to show the |
`\ presence of bugs, but is hopelessly inadequate for showing |
_o__) their absence.” —Edsger W. Dijkstra |
Ben Finney
More information about the Python-list
mailing list