Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将tkinter文件对话框与json.dump相结合_Python_Json_Tkinter - Fatal编程技术网

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
已是文件名谢谢!这有助于找到我的答案