Answer the question
In order to leave comments, you need to log in
Error TypeError: sequence item 0: expected str instance, dict found what to do?
import json
persones = []
def users_persone():
name = input('Введите имя контакта - ')
tel = input('Введите номер - ')
persone = {name: tel}
persones.append(persone)
MyFile = open('C:\HP\proverka.txt', 'w')
MyFile.writelines(persones)
MyFile.close()
with open('persones.json', 'w') as file:
json.dump(persones, file, ensure_ascii=False)
return persone
def main():
l = True
while l:
users_choise = input("Желаете ввести или получить контактные данные - ")
if users_choise == 'ввести':
users_persone()
elif users_choise == "получить":
print(MyFile)
users_choise_two = input("Желаете остановить програму - ")
if users_choise_two == 'да':
print("Програма закрыта")
l = False
main()
Answer the question
In order to leave comments, you need to log in
MyFile = open('C:\HP\proverka.txt', 'w')
MyFile.writelines(persones)
MyFile.close()
writelines() expects an array of STRINGS as input, and you give an array of dictionaries. Hence the error.
Why did you write this fragment at all, if you have normal saving in json a little further?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question