Python tkFileDialog.asksaveasfile - get file path

user3240368 picture user3240368 · Feb 19, 2014 · Viewed 9.5k times · Source

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.

Answer

Jan Wilmar picture Jan Wilmar · Oct 20, 2016

Try this:

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

It'll return:

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