[Tutor] Delete in .dat
ryan luna
ryan_gm at sbcglobal.net
Sun Mar 5 02:54:28 CET 2006
My question seems like itd be farly simple but i cant
seem to get it to work,
My .dat file is a dictionary and i need to be able to
only delete a single word and its definition,
heres what i have so far but it doesn't work.
pickle_file = open("dictionary.dat", "r")
dictionary = cPickle.load(pickle_file)
pickle_file.close()
sentence = raw_input("What definition would
you like to delete?: ")
if sentence in dictionary:
del dictionary[sentence]
print "\n\t", sentence, "Has been removed"
else:
print "\n\t", sentence, "That word is not
in the dictionary"
pickle_file = open("dictionary.dat", "w")
cPickle.dump(dictionary, pickle_file)
pickle_file.close()
More information about the Tutor
mailing list