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()
2

1 Answer 1

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"!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.