hi im trying to expand on my dictionary learning and i currently have two problems with this code:
import cPickle
file = open('phonebook.txt', 'w')
phonebook = {'Andrew Parson':8806336, \
'Emily Everett':6784346, 'Peter Power':7658344, \
'Lewis Lame':1122345}
cPickle.dump(phonebook,file)
raw_input("press enter to show how to add a key and a value")
phonebook['Ginger' ] = 1234567
cPickle.dump(phonebook,file)
print phonebook
p = float(raw_input("do you want to add a new person? (1 = yes, 0 = no)"))
s = float(raw_input("do you want to stay? (again 1 = yes, 0 = no)"))
if s == 1:
if p == 1:
n = raw_input("what is the persons name?")
nb = raw_input("what is there number?")
phonebook[n] = nb
cPickle.dump(phonebook,file)
v = float(raw_input("do you want to see the phonebook now? (1 = yes, 0 = no)"))
if v == 1:
print phonebook
else:
print "thank you for using a George Lee program"
raw_input("press enter to close")
else:
print "thank you for using a George Lee program"
raw_input("press enter to close")
else:
print "thank you for using a George Lee program"
raw_input("press enter to close")
print "thank you for using a George Lee program"
g = float(raw_input("are you sure you want to go? (again 1 = yes, 0 = no)"))
if g == 0:
if p == 1:
n = raw_input("what is the persons name?")
nb = raw_input("what is there number?")
phonebook[n] = nb
cPickle.dump(phonebook,file)
v = float(raw_input("do you want to see the phonebook now? (1 = yes, 0 = no)"))
if v == 1:
print phonebook
else:
print "thank you for using a George Lee program"
raw_input("press enter to close")
else:
print "thank you for using a George Lee program"
raw_input("press enter to close")
file.close()
first of all how can i make the txt file (phonebook.txt) easily readable?
secondly how can i edit the code so that it uses phonebook.txt as the dictionary phonebook
any help and advice welcome thanks