I am trying to write a contacts program and I have to write some information to txt file. I create a list and two dictionaries
name = ['charles', 'frank', 'chris']
phonenumbers = {'charles' : '12345', 'frank' : '23456', 'chris' : '34567'}
emails = {'charles' : '[email protected]', 'frank' : '[email protected]', 'chris' : '[email protected]'}
and I have two variables
ld_names = names, phonenumbers, emails
files = ('name_file.txt', 'phonenumber_file.txt', 'emails.txt')
I want to get a result like this
name_file.txt
['charles', 'frank', 'chris']
phonenumber_file.txt
{'charles': '12345', 'frank': '23456', 'chris': '34567'}
emails.txt
{'charles': '[email protected]', 'frank': '[email protected]', 'chris': '[email protected]'}
as you can see i have 3 txt files. it's too verbose if I write them one by one. and I try to use for loop
for file in files:
for ld_name in ld_names:
print(ld_name)
print(file
this is the code i try to write to the files.
while True:
mes = input('please press your key:')
if mes == 'quit':
for file in files:
with open(file, 'ab') as f:
for ld_name in ld_names:
pickle.dump(ld_name, f)
f.close()
break
but the result is not I want to get