Store a variable permanently

Jean-Michel Pichavant jeanmichel at sequans.com
Fri Mar 1 05:19:22 EST 2013


----- Original Message -----
> 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?
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

Hi,

I would serialize the data.

http://docs.python.org/2/library/pickle.html

funds=5
pickle.dump(funds, 'funds.pickle')

# to reload funds:

funds = pickle.load('funds.pickle')


The good thing with pickle is that it serializes a lot of things, see the "What can be pickled" section of the doc.


JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list