Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python tkFileDialog.asksaveasfile - get file path

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.

like image 235
user3240368 Avatar asked Jan 18 '26 23:01

user3240368


2 Answers

Try this:

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

It'll return:

'C:/Users/Desktop/Test/aaaa.txt'
like image 140
Jan Wilmar Avatar answered Jan 20 '26 13:01

Jan Wilmar


Use tkFileDialog.asksaveasfilename instead of tkFileDialog.asksaveasfile.

NOTE tkFileDialog.asksaveasfilename does not take mode parameter.

like image 32
falsetru Avatar answered Jan 20 '26 14:01

falsetru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!