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
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
Comment