[Tutor] Address book sort of (fwd)

Adam Cripps kabads at gmail.com
Sun Dec 5 09:47:47 CET 2004


On Sun, 5 Dec 2004 09:22:25 +0300 (Arab Standard Time), Eri Mendz
<jerimed at myrealbox.com> wrote:
> 
> 
> --
> Regards,
> Eri Mendz
> 
> ---------- Forwarded message ----------
> Date: Sat, 4 Dec 2004 15:53:36 +0300 (Arab Standard Time)
> Subject: Address book sort of
> 
> Dear Tutor,
> 
> I like to know what is the proper procedure (is algorithmn the right
> term?) in creating data in a program, write it to file, close the app
> then retrieve the data when run again. Basically, I'm trying to simulate
> a simple address book (well not really for the datas are just names for
> now) and so far have created the basic menu interface. It is console
> base so forget gui. I ask user input and store it in a list. There are
> menus to change, delete the data, and to save the data list in file. I
> use cPickle for this and have verified the file is created by checking
> in my $PWD. I want to retrieve that data when program is run again. What
> to add in my code? I thought not to post the code but explain it as
> above.
> 
> What i want: when program is run again, the saved data is loaded when user
> selects option 1 below. Of course the first time it is run, the list is
> empty.
> 
> def print_options():
>        print '''
>        Options:
>        [1] - Print content of list
>        [2] - Add name to list
>        [3] - Delete name from list
>        [4] - Change name in list
>        [5] - Save list to file
>        [P] - Print this menu
>        [Q] - Quit
>        '''
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

This sounds slightly similar to one of my first applications in Python
using object orientated design:

https://savannah.nongnu.org/projects/newmag

 - which is a magazine catalogue. Feel free to browse the code, and
reuse if you wish (under conditions of the license).

It creates objects, and then writes the objects (using pickle) to a
file - the process of opening is simple - you just open the file and
then Python reloads all the objects into memory again.

Adam

-- 
http://www.monkeez.org
PGP key: 7111B833


More information about the Tutor mailing list