如果要从这样的文本文件中删除换行符:
hello
there
我使用一个简单的代码,像这样:
with open('words.txt') as text:
for line in text:
print (line.strip())
它输出:
hello
there
但是,我希望我的代码输出以下内容:
hello
there
我怎样才能做到这一点?提前致谢。
if line.strip() == '': continue
在您的print
声明之前添加。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句