【发布时间】:2017-04-13 15:26:51
【问题描述】:
我正在尝试删除这两个分隔符之间的文本:''。我正在阅读电子邮件内容,然后将该内容写入 .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(技术术语)
-
名字奥斯汀姓氏琼斯
标签: python python-2.7 delimiter