Reputation: 295
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()
Upvotes: 1
Views: 217
Reputation: 11614
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"!
Upvotes: 1