我在python中遇到了問題。我想創建一個函數來從用戶打印一個文件到一個新文件(example.txt)。打印爲python中的字典
舊的文件是這樣的:
{'a':1,'b':2...)
,我想喜歡新的文件:
a 1,b 2(the next line)
但是我做可以運行的功能,但它並不顯示在任何新文件。有人能幫助我嗎。
def printing(file):
infile=open(file,'r')
outfile=open('example.txt','w')
dict={}
file=dict.values()
for key,values in file:
print key
print values
outfile.write(str(dict))
infile.close()
outfile.close()
也使用像'dict'這樣的名稱不推薦 –
您使用的命名約定有點不整齊。 – ABcDexter
你的意思是'dict'? –