我有一個名爲「list」的列表。它包含兩個字典。我正在以dict [count],dict [count + 1]的形式訪問這些字典。Python:如何將某個鍵的值寫入文件?
現在我必須檢查一個關鍵是作爲版本。然後我寫代碼爲
filename = "output.txt"
fo = open(filename, "a")
for key1,key2 in zip(dict[count].keys(),dict[count+1].keys()):
if key1 == 'version':
# print "value of version:", (dict[count])[key]
fo.write("value of version:",(dict[count])[key])
if key2 == 'version':
# print "value of version:", (dict[count+1])[key]
fo.write ("value of version:", (dict[count+1])[key2])
這裏我能夠打印版本的值,但我無法寫入文件。
Errror:類型錯誤:功能恰恰1個參數(2給出)
fo.write(「value of version:」** + **(dict [count])[key]) – deathangel908
Thanks deathangle908。其工作 – SSH
避免使用字典和列表作爲變量名稱。這是危險的,會帶來不希望的結果。 – lima