Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40244

Re: Store a variable permanently

Date 2013-03-01 11:19 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: Store a variable permanently
Newsgroups comp.lang.python
Message-ID <mailman.2716.1362133572.2939.python-list@python.org> (permalink)

Show all headers | View raw


----- 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.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Store a variable permanently Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-03-01 11:19 +0100
  Re: Store a variable permanently Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-02 02:29 +0000

csiph-web