[Tutor] Saving and loading data to/from files
Daryl G
gman_95@hotmail.com
Sat, 02 Jun 2001 23:52:15 -0000
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=[]
L_Name=[]
PH_num=[]
total=0
#savedata method
def savedata():
filename= raw_input("Enter the name you wish to give this address book:
")
object=(F_Name, L_Name, PH_num, total)
file=open(filename, 'w')
pickle.dump(object, file)
#opendata method
def opendata():
filename=raw_input("Enter the name of the Addressbook you wish to open:
")
file = open(filename,'r')
(F_Name,L_Name, PH_num, total)=pickle.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