Remove empty lines
Kristin Skoglund
krists at ifi.uio.no
Wed Mar 20 12:00:21 EST 2002
Hi
I am trying to make a script that reads javafiles and remove comments
and empty lines. The script looks like this......
def removestuff(file):
infilename=file
infile=open(infilename, 'r')
copyfile=infilename +".bak"
newfile=open(copyfile,'w')
str = infile.read()
str=re.sub(r"/\*\*\n.*\n*\*/|/\*\n.*|\*.*|\s*/\s*"," ",str) #This strips away comments
lines=re.split("\n",str)
for line in lines: # Here I try to remove the emty lines
if line== '':
continue
elif empty:
continue
else:
tmp.append(line)
newfile.write(line)
infile.close()
newfile.close()
...and everything works except the removal of empty lines. Does anyone
knoe whats wrong?
Kristin
More information about the Python-list
mailing list