How to remove empty lines with re?
ted
tedNOSPAM94107 at yahoo.com
Fri Oct 10 03:46:23 EDT 2003
I'm having trouble using the re module to remove empty lines in a file.
Here's what I thought would work, but it doesn't:
import re
f = open("old_site/index.html")
for line in f:
line = re.sub(r'^\s+$|\n', '', line)
print line
Also, when I try to remove some HTML tags, I get even more empty lines:
import re
f = open("old_site/index.html")
for line in f:
line = re.sub('<.*?>', '', line)
line = re.sub(r'^\s+$|\n', '', line)
print line
I don't know what I'm doing. Any help appreciated.
TIA,
Ted
More information about the Python-list
mailing list