【发布时间】:2021-11-11 14:56:46
【问题描述】:
我正在尝试从命令行读取文件,并尝试在该文件中使用空白 replace all the commas。以下是我的代码:
import sys
datafile = sys.argv[1];
with open(datafile, 'r') as data:
plaintext = data.read()
plaintext = plaintext.replace(',', '')
print(plaintext)
但是在打印明文时,我得到了one extra blank row at the end。为什么会发生这种情况,我该如何摆脱它?
【问题讨论】:
标签: python python-3.x file