3

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.

falsetru
  • 357,413
  • 63
  • 732
  • 636
user3240368
  • 119
  • 1
  • 2
  • 6

4 Answers4

5

Try this:

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

It'll return:

'C:/Users/Desktop/Test/aaaa.txt'
Jan Wilmar
  • 157
  • 4
  • 12
3

Use tkFileDialog.asksaveasfilename instead of tkFileDialog.asksaveasfile.

NOTE tkFileDialog.asksaveasfilename does not take mode parameter.

falsetru
  • 357,413
  • 63
  • 732
  • 636
0

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

0

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

MR. JD
  • 39
  • 1
  • 1
  • 3