1 回答
![?](http://img1.sycdn.imooc.com/533e4c0500010c7602000200-100-100.jpg)
TA贡献1825条经验 获得超4个赞
我认为你的问题就在这里:
export_dir + str(MRBTS) +'_IPV6.xml'
askdirectory()
不包括尾部斜杠。你真正想要的是:
f'{export_dir}\{MRBTS}_IPV6.xml'
然而,更清洁的方法如下所示:
from tkinter import Tk, filedialog
from os import path
root = Tk()
root.geometry('800x600')
root.title("Test")
#with one function handling all the save logic
#~it becomes harder to make mistakes and easier to find them
def save_utf8(filename, data):
folder = filedialog.askdirectory()
filepath = path.join(folder, filename)
with open(filepath, 'wb') as f:
f.write(data.encode('utf-8'))
#represents some data that your app concocted
MRBTS = 'blahblah'
xmldata = '<blah>BLAH</blah><blah>BLAH</blah><blah>BLAH</blah>'
#utilize the save function
save_utf8(f'{MRBTS}_IPV6.xml', xmldata)
root.mainloop()
添加回答
举报