问题
I want to get path of file "exportFile".
exportFile = tkFileDialog.asksaveasfile(mode='a')
If I write "print exportFile", I get:
<open file u'C:/Users/Desktop/Test/aaaa.txt', mode 'a' at 0x02CB6078>
But I need only path - "C:/Users/Desktop/Test/aaaa.txt". Is there any solution? Thank you.
回答1:
Use tkFileDialog.asksaveasfilename instead of tkFileDialog.asksaveasfile
.
NOTE tkFileDialog.asksaveasfilename
does not take mode
parameter.
回答2:
Try this:
exportFile = tkFileDialog.asksaveasfile(mode='a')
exportFile.name
It'll return:
'C:/Users/Desktop/Test/aaaa.txt'
回答3:
Try tkFileDialog.askdirectory
instead of any file name dialog. That will return a directory instead of a file name.
来源:https://stackoverflow.com/questions/21877216/python-tkfiledialog-asksaveasfile-get-file-path