user3240368
user3240368

Reputation: 119

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.

Upvotes: 3

Views: 13298

Answers (4)

MR. JD
MR. JD

Reputation: 49

Instead of printing 'exportFile' try to print 'exportFile.name'. It should give the output you desire

Upvotes: 0

Jan Wilmar
Jan Wilmar

Reputation: 167

Try this:

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

It'll return:

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

Upvotes: 6

Andy Richter
Andy Richter

Reputation: 1

Try tkFileDialog.askdirectory instead of any file name dialog. That will return a directory instead of a file name.

Upvotes: 0

falsetru
falsetru

Reputation: 369064

Use tkFileDialog.asksaveasfilename instead of tkFileDialog.asksaveasfile.

NOTE tkFileDialog.asksaveasfilename does not take mode parameter.

Upvotes: 4

Related Questions