Store a variable permanently

E

eli m

So i have a variable called funds that i want to store the value of even after the program is exited. My funds variable holds the total value of fundsi have. I add a certain number of funds each time i run the program by entering how much i want to add. How would i store the funds variable to keep its value?
 
S

Steven D'Aprano

So i have a variable called funds that i want to store the value of even
after the program is exited. My funds variable holds the total value of
funds i have. I add a certain number of funds each time i run the
program by entering how much i want to add. How would i store the funds
variable to keep its value?

You have to write it to a file, then read it back in when the program
starts.

Do you need help with reading and writing files?

Perhaps the easiest way to do this is with the configparser or plistlib
modules.

http://docs.python.org/2/library/configparser.html
http://docs.python.org/2/library/plistlib.html
 
M

Mitya Sirenef

So i have a variable called funds that i want to store the value of even after the program is
exited. My funds variable holds the total value of funds i have. I add a
certain number of funds each time i run the program by entering how much
i want to add. How would i store the funds variable to keep its value?


Take a look at these examples from shelve module doc page:

http://docs.python.org/2/library/shelve.html#example

-m
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top