-1

I am writing a program where basically you type information, and the information is saved in a text file. The program has to know where to save that specific text file. I have added a menu button that directs you to an area of the program where you can tell the program where you would like the program to save the file. The problem is that I would like to have to tell the program where I would like to save the file once, and only once. So after I close the program I could open it back up, and it would remember where I would like to save the file.

This is not my exact code, just an example:

flub = raw_input("Where would you like to save your file?)
SaveDirectory = flub

In this case, SaveDirectory is where I want to save the file. I would like the program to ask me where I would like to save the program once, and only once.

0

I thought I had answered this for you before, but if your still really stuck try something like this, you should be able to go from here (Note: in this example "datafile.txt" must exist first):

import os 
flub = raw_input('Where would you like your save directory to be?')

file = open("datafile.txt", "r")
filedata = file.read()
file.close()

try:
    if os.stat("datafile.txt").st_size > 0:
        print "Value exists already"
else:
    file = open("datafile.txt", "w")
    file.write(flub)
    file.close()
    print "flub value updated to: " + flub
except OSError:
    print "No file"
  • I got what you were trying to say, and I tweaked your program a lot, and found what I was looking for. Thank you! – Mezex Jun 12 '14 at 19:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.