ı am new at using python pickle and
Question: each dictionary has the form: records[name]=[email,telephone] the dictionary
is pickled and stored in a file name recordsfile .

the big problem after if ı made above...

adds new record to the addresbook ?

thanks for helping ..


Answer: Well, if I understand your question correctly (Please try and be more clear
next time, also use better grammar as we all know anyone who comes on this
site can), you would have to unpickle the dictionary, add a key:value pair,
than pickle it again. For example,

    
    
    import cPickle as pickle
    
    addressBook = {"Foo": "555-555-5555, foo@bar.com"}
    
    for key, var in addressBook.iteritems():
        print key, ":", var
    
    print
    
    addressFile = open("address.pickle", "wb")
    pickle.dump(addressBook, addressFile)
    addressFile.close()
    
    #Now to add a new value to addressBook
    
    addressFile = open("address.pickle", "rb")
    addressBook = pickle.load(addressFile)
    addressFile.close()
    
    addressBook["Bar"] = "012-345-6789, bar@foo.com"
    
    for key, var in addressBook.iteritems():
        print key, ":", var
    
    addressFile = open("address.pickle", "wb")
    pickle.dump(addressBook, addressFile)�ddressBook, addressFile)
    

Now, I just threw that together in a couple of minutes, so it can obviously be
cleaned up. However, it does show you the basics of how to do what you're
asking for.

