Python tkFileDialog.asksaveasfile - 获取文件路径

use*_*368 3 python tkinter savefiledialog python-2.7

我想获取文件“exportFile”的路径。

exportFile = tkFileDialog.asksaveasfile(mode='a')
Run Code Online (Sandbox Code Playgroud)

如果我写“打印导出文件”,我会得到:

<open file u'C:/Users/Desktop/Test/aaaa.txt', mode 'a' at 0x02CB6078>
Run Code Online (Sandbox Code Playgroud)

但我只需要路径 - “C:/Users/Desktop/Test/aaaa.txt”。有什么解决办法吗?谢谢。

小智 6

尝试这个:

exportFile = tkFileDialog.asksaveasfile(mode='a')
exportFile.name
Run Code Online (Sandbox Code Playgroud)

它会返回:

'C:/Users/Desktop/Test/aaaa.txt'
Run Code Online (Sandbox Code Playgroud)