[Tutor] How do I save a dictionary to disk? (another newbie question)

Frank Holmes flash1210@hotmail.com
Thu, 10 Jan 2002 20:28:30 -0800


   I am working on a simple program for recalling phone numbers. I am using 
a dictionary to deal with variations in spelling, etc. I took the dictionary 
out of the 'while' loop and the add_name() function works as planned.... 
except (duh..) when I quit the program and restart it the names I have added 
are no longer there. They exist only locally and are dumped when the program 
ends.
   I beat my head against this for a few hours today, went through my books 
and cannot figure out how to store the updated dictionary.
   I know this is probably easy stuff but I am completely stumped.

   I am using python on a windows98 system.

def add_name():
     print "Enter Name"
     n=raw_input()
     d1[n]=m

d1={'name':'1111', 'a. name':'1111', 'different name':'2222'}
while 1:
     print "A Greeting"
     print "Please enter name to search"
     print "Type 'add' to add entries or 'quit' to exit"
     x=raw_input()
     if x=='quit':
          break
     if x in d1.keys():
          print d1[x], x
     if x=='add':
          add_name()


_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com