I have a python script using Tkinter. In the script I have a numeric variable that the user is able to change the value of by entering the value in an entry box. I presently have the script reading and writing the value to an external .txt file so when the program is exited and restarted the previous value of the variable is retained. I have been unsuccessful in finding a way to store the value inside the script file. Is this possible? If so, could someone point me in the direction of a way to do this so the script would not have to depend on an external file?
Thanks
aframe 1 Newbie Poster
Recommended Answers
Jump to PostI think there is a way to get the path to the .py file.
sys.argv[0]
might work.
I'm not sure though.
Jump to Postimport configparser import os import sys config = configparser.ConfigParser() #If the script is executed __name__ will be '__main__' and sys.argv[0] will be the full path of the script. if __name__ == '__main__': path = os.path.dirname(sys.argv[0]) #Else the script was imported as a module and it has a …
Jump to PostResponse to tonyjv: it is a horrible idea to self-modify your code. You can make wonderful messes, though it is kind of fun if you don't have to maintain it. I *think* that the fact the script is byte compiled means you can get away with writing to the .py …
Jump to PostUsing files can be a better option than using the registry for storing settings in certain situations, especially when users may wish to alter application settings externally and save them for later use.
Storing settings in files can also provide greater cross platform support, especially when the user may …
All 16 Replies
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
jcao219 18 Posting Pro in Training
aframe 1 Newbie Poster
jcao219 18 Posting Pro in Training
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
aframe 1 Newbie Poster
jcao219 18 Posting Pro in Training
aframe 1 Newbie Poster
jcao219 18 Posting Pro in Training
lrh9 95 Posting Whiz in Training
griswolf 304 Veteran Poster
lrh9 commented: Some good catches. Some bad advice. Otherwise good reply. +1
lrh9 95 Posting Whiz in Training
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
griswolf 304 Veteran Poster
lrh9 95 Posting Whiz in Training
griswolf 304 Veteran Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.