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


Groups > comp.lang.python > #40244

Re: Store a variable permanently

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=7652b43bb=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status UNSURE 0.203
X-Spam-Level **
X-Spam-Evidence '*H*': 0.60; '*S*': 0.01; 'cc:addr:python-list': 0.10; 'add.': 0.16; 'exited.': 0.16; 'reload': 0.16; 'subject:Store': 0.16; 'subject:variable': 0.16; 'variable': 0.20; 'holds': 0.20; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'run': 0.28; 'pickle': 0.29; 'things,': 0.29; 'url:mailman': 0.29; "skip:' 10": 0.30; 'url:python': 0.32; '-----': 0.32; 'url:listinfo': 0.32; 'certain': 0.33; 'hi,': 0.33; 'add': 0.36; 'url:org': 0.36; 'data.': 0.36; 'url:library': 0.36; 'thank': 0.36; 'skip:p 20': 0.36; 'subject:: ': 0.38; 'store': 0.38; 'url:docs': 0.38; 'called': 0.39; 'url:mail': 0.40; 'you.': 0.61; 'received:194': 0.61; 'information': 0.63; 'total': 0.65; 'person,': 0.65; 'disclose': 0.69; 'notice:': 0.71; 'privileged.': 0.72; 'funds': 0.78; '"what': 0.84; 'funds:': 0.84; 'medium.': 0.91; 'have.': 0.95
X-IronPort-AV E=Sophos;i="4.84,761,1355094000"; d="scan'208";a="1243711"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Fri, 1 Mar 2013 11:19:22 +0100 (CET)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To eli m <techgeek201@gmail.com>
In-Reply-To <8df443ef-9199-421d-b38a-56b60d04de75@googlegroups.com>
Subject Re: Store a variable permanently
MIME-Version 1.0
X-Mailer Zimbra 7.2.0_GA_2669 (ZimbraWebClient - GC7 (Linux)/7.2.0_GA_2669)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
X-Mailman-Approved-At Fri, 01 Mar 2013 11:26:11 +0100
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2716.1362133572.2939.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362133572 news.xs4all.nl 6933 [2001:888:2000:d::a6]:35213
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40244

Show key headers only | 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