pythonian way

Antti Kuntsi kuntsi at cc.helsinki.fi.spam.no
Fri Feb 25 06:49:35 EST 2000


Fredrik Lundh <effbot at telia.com> wrote:
> readlines returns an empty line as "\n", not as
> an empty string.  replacing None with a suitable
> lambda expression might help:
>     A = filter(lambda s: len(s) > 1, H.readlines())
> or (easier to read), ignore empty lines (and maybe
> comments too?) in the processing loop.  e.g.
>     for line in H.readlines():
>         if line[:1] in "#\n":
>             continue # skip this one
>         ...

Perhaps
	import string
	A = filter(string.strip, H.readlines())
could do the trick? I know, it's not fast. How about:
	import string
	A = filter(None, map(string.strip, H.readlines()))

.antti


--
______________________________________________________________
|O| ----------------------------------------------------------
| | |Twisted mind? No, just bent in several strategic places.|
`\| |___________________________________mickut at iki.fi/mickut/|



More information about the Python-list mailing list