-1
flub = raw_input("Where would you like your save directory to be?)
SaveDir = flub

Hello ubuntu, I am writing a python program. My question is, how can I make it so a raw_input asks me a question that defines a variable (in this case variable is flub), then changes the code so that the variable is always the same. When I change the flub variable in the program, I would like it to always remember what I changed the variable to.

Note: this code is just an example, I am really working with an advanced program with a graphical interface, and I didn't want to post it here on the ubuntu fourms. If you have any questions, please ask.

Thanks ubuntu :)

  • I would assign your variable to a constant after acquiring your variable and using the constant for the remainder of the program so something like: what is x?; x = 1, constant = x, y = constant * 5 or something like that. follow the logic not the code lol, I know it isn't right. – TheXed Jun 12 '14 at 17:21
  • I am not pretty sure, but since python is dynamically typed, I don't think you can do what you are trying to. There is no const in python and the interpreter too does not enforce type checking, so I believe this rather might have workarounds (which I am not aware of though) than solutions. – jobin Jun 12 '14 at 17:34
  • Shouldn't this be on Stack Overflow? – Tim Jun 12 '14 at 17:54
  • Yes @Tim, it should, but you see. Many years ago, I posted a question that got many bad reviews, and now I am no longer allowed to post on StackOverflow :( – Mezex Jun 12 '14 at 17:57
  • @Mezex you have 6, and haven't been banned by the look of it, so you should be able too. None of them have been voted down that much... – Tim Jun 12 '14 at 18:00
2

I think flub = raw_input('Where would you like your save directory to be?') print flub

Will get your variable, pass that to your GUI.

Unless you change it later on in the program, it will remain until restarted / retriggered. To store that value permanently, you would need to write it somewhere lets say a text file, or set your program up to set a true false checking whether that variable has been set yet.

  • This doesn't help me. I may not have been specific enough. What I need is for that input to change the variable, then no matter if the program is restarted, or the computer is shut down, the variable will not change again. – Mezex Jun 12 '14 at 17:34
  • Maybe I misunderstand slightly, read this: stackoverflow.com/questions/13830334/… saving to a text file for reference like this is what I meant – Duncubuntu Jun 12 '14 at 17:36
  • Also, as far I understand it, once a Python program is loaded, you can write to it. You could set flub manually, by having Python overwrite those lines in its code with the updated variable. THen just check to see if flub was set before asking. That should do it. – Duncubuntu Jun 12 '14 at 17:38
  • Ohhh, okay. I got it from that link you gave me. Thanks for the help! @Duncubuntu – Mezex Jun 12 '14 at 17:45

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