Remove empty lines

Nick Arnett narnett at mccmedia.com
Wed Mar 20 13:33:55 EST 2002


> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Bengt Richter
> Sent: Wednesday, March 20, 2002 10:14 AM
> To: python-list at python.org
> Subject: Re: Remove empty lines

[snip]

> >
> >    lines=re.split("\n",str)
> >
> >    for line in lines:   # Here I try to remove the emty lines
> >
> >        if line== '':

The problem is here, I think.  Split in Python appears to return the
separator, so the '\n' characters are still there.  If that's the problem,
this should fix it.

if line == '\n':

At least, that's my suspicion, without testing.  (In Perl, the separators
are not returned by default, so if you came to Python from Perl, like me,
this is confusing.)

Nick





More information about the Python-list mailing list