Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def delete_contact():
- del_id = input('Введите id записи, которую необходимо удалить: ')
- id = int(del_id)
- try:
- with open(path_to_db, 'r', encoding='UTF-8') as file:
- data = json.load(file)
- for i in range(0, id):
- if data[i]['id'] == id:
- print('data', data[i])
- print('id', id)
- del data[i]
- # if name not in data:
- # print('Такого контакта нет')
- with open(path_to_db, 'w', encoding='UTF-8') as file:
- json.dump(data, file, indent=4)
- print('\nКонтакт успешно изменена удалён!\n')
- controller.user_choice()
- except:
- print('Записи с таким id не существует\n')
- sleep(2)
- controller.user_choice()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement