I have problem with changing a dict value and saving the dict to a text file (the format must be same), I only want to change the member_phone
field.
My text file is the following format:
memberID:member_name:member_email:member_phone
and I split the text file with:
mdict={}
for line in file:
x=line.split(':')
a=x[0]
b=x[1]
c=x[2]
d=x[3]
e=b+':'+c+':'+d
mdict[a]=e
When I try change the member_phone
stored in d
, the value has changed not flow by the key,
def change(mdict,b,c,d,e):
a=input('ID')
if a in mdict:
d= str(input('phone'))
mdict[a]=b+':'+c+':'+d
else:
print('not')
and how to save the dict to a text file with same format?
change
not doing what is expected (without proper debugging details), and the second is what everyone answered. For that one there are many other versions of the question that look better asked, even if they ended up less popular. So I've gone ahead and dupehammered this. – Vanatta