Python tkFileDialog.asksaveasfile - 获取文件路径

3

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

exportFile = tkFileDialog.asksaveasfile(mode='a')

如果我写“print exportFile”,我会得到以下结果:
<open file u'C:/Users/Desktop/Test/aaaa.txt', mode 'a' at 0x02CB6078>

但我只需要路径 - “C:/Users/Desktop/Test/aaaa.txt”。 有什么解决方案吗?谢谢。
4个回答

6
试试这个:
exportFile = tkFileDialog.asksaveasfile(mode='a')
exportFile.name

它将返回:

'C:/Users/Desktop/Test/aaaa.txt'

4

0
尝试使用tkFileDialog.askdirectory而不是任何文件名对话框。这将返回一个目录而不是文件名。

0

不要打印“exportFile”,而是尝试打印“exportFile.name”。这样应该会得到您想要的输出结果。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接