我试图删除这两个分隔符之间的文本:'<'&'>'。我正在阅读电子邮件内容,然后将该内容写入.txt文件。我在这两个分隔符之间得到了很多垃圾,包括我的.txt文件中的行之间的空格。我如何摆脱这一点?下面是我的脚本已经从写我的.txt文件读入数据:如何在包含空行的两个分隔符之间剥离文本?
First Name</td>
<td bgcolor='white' style='padding:5px
!important;'>Austin</td>
</tr><tr>
<td bgcolor='#f9f9f9' style='padding:5px !important;'
valign='top' width=170>Last Name</td>
下面是我目前从它剥离了空行.txt文件读取代码:
# Get file contents
fd = open('emailtext.txt','r')
contents = fd.readlines()
fd.close()
new_contents = []
# Get rid of empty lines
for line in contents:
# Strip whitespace, should leave nothing if empty line was just "\n"
if not line.strip():
continue
# We got something, save it
else:
new_contents.append(line)
for element in new_contents:
print element
这里是预计什么:
First Name Austin
Last Name Jones
您可以为您的示例发布您的预期输出吗? –
同上@ Farhan.K,但增加了一些输入/预期/有doohickeys(技术术语) – Blacksilver
名\t \t奥斯汀\t \t 姓\t \t琼斯 –