如果我想从文本文件中删除换行符,如下所示:
hello
there
我使用这样的简单代码:
with open('words.txt') as text:
for line in text:
print (line.strip())
它输出这个:
hello
there
但是,我希望我的代码输出以下内容:
hello
there
我怎样才能做到这一点?提前致谢。
add if line.strip() == '': continue
在你之前print
陈述。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)