[英]Extra blank line is getting printed at the end of the output in Python
我正在嘗試從命令行讀取文件並嘗試用空白replace all the commas
該文件中的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
。 為什么會發生這種情況,我該如何擺脫它?
你也許可以使用
plaintext.rstrip('\n')
這應該刪除額外的行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.