Python 将tkinter文件对话框与json.dump相结合
我花了大半个小时研究这个问题,我敢肯定,这是一个非常简单的问题Python 将tkinter文件对话框与json.dump相结合,python,json,tkinter,Python,Json,Tkinter,我花了大半个小时研究这个问题,我敢肯定,这是一个非常简单的问题 我所要做的就是使用json.dump()从程序中导出字典。 我想使用tk.filedialog.asksaveas选择路径 def exportCSV(container): exCsDi = filedialog.asksaveasfilename() if not exCsDi: return with open (exCsDi.name) as file: json.dump(container.Dict, o
我所要做的就是使用
json.dump()
从程序中导出字典。
我想使用tk.filedialog.asksaveas
选择路径
def exportCSV(container):
exCsDi = filedialog.asksaveasfilename()
if not exCsDi:
return
with open (exCsDi.name) as file:
json.dump(container.Dict, open(file ,'w'))
file.close()
container.leavemini()
不过,这不起作用。
我得到AttributeError:“str”对象没有属性“name”
我以前成功地使用过json.dump()
,但这次我似乎看不出我的错误
谢谢大家! 因此,在Michael K.帮助我找到另一个问题后,我找到了解决方案:
def exportCSV(container):
exCsDi = filedialog.asksaveasfilename()
if not exCsDi:
return
with open (exCsDi, 'w') as file:
json.dump(container.Dict, file)
container.destroy()
从第5行中删除
.name
exCsDi
已是文件名谢谢!这有助于找到我的答案