Remove empty lines

Terry Reedy tejarex at yahoo.com
Wed Mar 20 12:20:30 EST 2002


"Kristin Skoglund" <krists at ifi.uio.no> wrote in message
news:3C98C025.7741BA58 at ifi.uio.no...

> I am trying to make a script that reads javafiles and remove
comments
> and empty lines. The script looks like this......
>     lines=re.split("\n",str)
>     for line in lines:   # Here I try to remove the emty lines
>         if line== '':
>             continue
>         elif empty:
>            continue
What is empty?  Not set in code you posted

>         else:
>             tmp.append(line) # not needed for example
>             newfile.write(line)

> ...and everything works except the removal of empty lines. Does
anyone
> knoe whats wrong?

No.  I would make a file with known contents: completely blank, with
spaces, same part with comments, bracketed by nonblank lines.  Then
print out before or after split to see what have after
comment-removing substitution.

Terry J. Reedy






More information about the Python-list mailing list