我的代碼正在工作,但我有一個輕微的缺陷,我似乎無法修復它。我的代碼是:TextFile到一個字典
def Identifierare():
File = open("FulaOrd.txt","r", encoding="utf-8")
for line in File:
if line.strip():
Dict = {}
key, value = line.split(None, 1)
Dict[key] = value
print(Dict)
Identifierare()
我的結果是
{'debt': '3\n'}
{'income': '2\n'}
{'mortgage': '2\n'}
{'sale': '2\n'}
如何帶走反斜線N +在原來的文本文件,字寫得像這樣 債務3 收入2 抵押貸款2 銷售2
感謝一大堆!
哦,忘了通知它是Python! – 2014-11-21 23:01:19
'line.rstrip()。split()' – 2014-11-21 23:08:34