1

I've got to make a program which creates a file at the beginning and then overwrite it. I've got something like this below and It works, but I wondered if there is a possibility to ask user where It should be created? For example just like It's done in MS Office?

# -*- coding: utf-8 -*-

import os.path

path = ('C:\\Python27\\')
name = raw_input('Enter file name: ')
save = os.path.join(path, name+'.txt')
save2 = open(save , 'a')
contents = raw_input('Contents')
save2.write(contents)
save2.close()
d33tah
  • 8,728
  • 10
  • 51
  • 128
Maq92
  • 245
  • 1
  • 3
  • 13
  • yeah, something like this. You know it shows You a new window where You can choose destiny path of that file – Maq92 Dec 11 '13 at 12:13
  • 2
    Have a look at http://stackoverflow.com/questions/7094324/how-to-use-python-saveas-dialog and http://code.activestate.com/recipes/438123-file-tkinter-dialogs/ and http://stackoverflow.com/questions/9319317/quick-and-easy-file-dialog-in-python – YXD Dec 11 '13 at 12:17

1 Answers1

1

Quickest way is with the included Tkinter packages:

from tkFileDialog import askopenfilename

fname = askopenfilename()

Like it's described a million times already: just try google: "python file dialog"!

Don Question
  • 10,018
  • 4
  • 32
  • 50