Is there a better/simpler way to filter blank lines?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue Nov 4 16:30:24 EST 2008


tmallen:
> I'm parsing some text files, and I want to strip blank lines in the
> process. Is there a simpler way to do this than what I have here?
> lines = filter(lambda line: len(line.strip()) > 0, lines)

xlines = (line for line in open(filename) if line.strip())

Bye,
bearophile



More information about the Python-list mailing list