我在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'? –