pythonian way
Gerrit Holl
gerrit.holl at pobox.com
Fri Feb 25 07:29:31 EST 2000
<quote name="Alexander Williams" date="951467193">
> On Fri, 25 Feb 2000 09:49:15 +0100, Milos Prudek <prudek at nembv.cz> wrote:
> >> A = H.readlines()
> >
> >Yeah, but I need to remove empty lines as well...
>
> Try:
>
> >>> A = filter(None, H.readlines())
>
> filter() with None as the function to use as the test for elements
> removes any that test as False intrinsically; since the empty line is
> always False, it returns a list with only strings with length. Bingo.
A line with only a newline is true, so I think Milos meant:
A = filter(string.strip, H.readlines())
regards,
Gerrit.
--
Comparison Python GUI's: http://www.nl.linux.org/~gerrit/gui.html
Please comment!
More information about the Python-list
mailing list