Python tkFileDialog.asksaveasfile - 获取文件路径

标签 python python-2.7 tkinter savefiledialog

我想获取文件“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”。 有什么解决办法吗?谢谢。

最佳答案

试试这个:

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

它将返回:

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

关于Python tkFileDialog.asksaveasfile - 获取文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21877216/

相关文章:

python:缺少1个必需的位置参数: 'self'

python - 在 pandas 数据框中将日期转换为日期时间格式时出现问题

python - 在pycharm和kivy中更新骨架

python - 使用 4 个参数对数据集进行聚类和标记

python - 使用 os.popen3() 在 python 中提取视频的缩略图

python - Tkinter:根上的滚动条而不是另一个窗口

python - scrapy 的问题 - 没有抓取任何项目

python-2.7 - 如何识别这个圆边?

Python SciPy 索引错误 : the length of bounds is not compatible with that of x0

python - Python使用别人文件时的缩进问题