Store a variable permanently

Discussion in 'Python' started by eli m, Mar 1, 2013.

  1. eli m

    eli m Guest

    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?
     
    eli m, Mar 1, 2013
    #1
    1. Advertising

  2. On Thu, 28 Feb 2013 19:35:57 -0800, eli m wrote:

    > 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


    --
    Steven
     
    Steven D'Aprano, Mar 1, 2013
    #2
    1. Advertising

  3. On 02/28/2013 10:35 PM, eli m wrote:
    > 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


    --
    Lark's Tongue Guide to Python: http://lightbird.net/larks/

    Fashion is something barbarous, for it produces innovation without reason
    and imitation without benefit. George Santayana
     
    Mitya Sirenef, Mar 1, 2013
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve - DND
    Replies:
    0
    Views:
    385
    Steve - DND
    May 15, 2004
  2. Michael Torrie

    Re: Store a variable permanently

    Michael Torrie, Mar 1, 2013, in forum: Python
    Replies:
    3
    Views:
    138
    Modulok
    Mar 2, 2013
  3. Steven D'Aprano

    Re: Store a variable permanently

    Steven D'Aprano, Mar 2, 2013, in forum: Python
    Replies:
    0
    Views:
    121
    Steven D'Aprano
    Mar 2, 2013
  4. Steven D'Aprano

    Re: Store a variable permanently

    Steven D'Aprano, Mar 12, 2013, in forum: Python
    Replies:
    0
    Views:
    86
    Steven D'Aprano
    Mar 12, 2013
  5. Steven D'Aprano

    Re: Store a variable permanently

    Steven D'Aprano, Mar 13, 2013, in forum: Python
    Replies:
    1
    Views:
    125
    Chris Angelico
    Mar 14, 2013
Loading...

Share This Page