Removing Duplicate entries in a file...

Fuzzyman fuzzyman at
Fri Jan 6 10:45:21 CET 2006

sri2097 wrote:
> Hi all, I'm storing number of dictionary values into a file using the
> 'cPickle' module and then am retrieving it. The following is the code
> for it  -
> # Code for storing the values in the file
> import cPickle
> book = {raw_input("Name: "): [int(raw_input("Phone: ")),
> raw_input("Address: ")] }
> file_object = file(database, 'w+')
> cPickle.dump(book, file_object)
> file_object.close()

I may be misunderstanding you - but it seems you just want to read a
pickle, modify it, and then write it back ?

What you're doing is appending the modified pickle to the original one
- which is more complicated than what you want to achieve.

file_object = open(filename, 'rb')
stored_dict = cPickle.load(file_object)

... code that modifies stored_dict

file_object = open(filename, 'wb')
cPickle.dump(stored_dict, file_object)

Any reason why that shouldn't do what you want ?

All the best,


More information about the Python-list mailing list