[Tutor] Saving and loading data to/from files

cynic@mail.cz cynic@mail.cz
Sat, 2 Jun 2001 21:11:25 -0400


Hi there,

I'm not very familiar with Python, but IIRC pickle is meant for serializing data, which is not the same as general persis=
tance using files, databases and alike. I'd suggest you use a csv file to save your addresses, read the file a line at a =
time, and split it into your variables. the file would look st. like this:

XXXXXXXXX start of file XXXXXXXXXXX
Doe;Joe;123456
Black;Tom;987654
Clinton;Bill;111222
XXXXXXXXX end of file XXXXXXXXXXX


Original Message:
-----------------
From: Daryl G gman_95@hotmail.com
Date: Sat, 02 Jun 2001 23:52:15 -0000
To: tutor@python.org
Subject: [Tutor] Saving and loading data to/from files


Hi,  I am having difficulty in saving and loading data that I created in a 
simple Address book program. I  am using 3 list variables for First and Last 
name and phone number and an interger that counts the total number of 
entries.  I first tried using the 'write' but that wouldn't work with lists. 
I discovered the pickle module and
I am able to save my data, but when I load it back up and then try to view 
it in my program, its not there.

variables
import pickle, string

F_Name=3D[]
L_Name=3D[]
PH_num=3D[]
total=3D0

#savedata method
def savedata():
    filename=3D raw_input("Enter the name you wish to give this address book: 
")
    object=3D(F_Name, L_Name, PH_num, total)
    file=3Dopen(filename, 'w')
    pickle.dump(object, file)

#opendata method
def opendata():
    filename=3Draw_input("Enter the name of the Addressbook you wish to open: 
")
    file =3D open(filename,'r')
    (F_Name,L_Name, PH_num, total)=3Dpickle.load(file)


What am I doing wrong?
Another question that I have is how do I format data that I want to display 
in specific
columns in standerd output, like that can be done in C ?
Thanks
Daryl
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

--------------------------------------------------------------------
Mail2Web - Check your email from the web at
http://www.mail2web.com/ .