H
H
hlystik2021-11-06 20:14:39
Python
hlystik, 2021-11-06 20:14:39

How to make the text in the JSON module saved as Cyrillic?

If that produces such characters.
6186b8b12fcc4887680330.png

The code where I use this.

import json

def users_persone():
  name = input('Введите имя контакта - ')
  tel = input('Введите номер - ')

  persone = {

  name:tel

  }
  return persone

def main():

  l = True
  while l:
    
    def main_2():
      try:
        data = json.load(open('persones.json'))
      except:
        data = []

      data.append(users_persone())

      with open('persones.json', 'w') as file:
        json.dump(data, file, indent = 2, ensure_ascii = False)

      print('Контакт добавлен ^_^')

    users_choise = input("Желаете ввести или получить контакт - ")



    if users_choise == 'ввести':
      main_2()


    elif users_choise == 'отримати':
      users_input_name = input("Введіть ім'я користувача для номеру - ")


    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

1 answer(s)
V
Vindicar, 2021-11-06
@hlystik

As I wrote in your other question, specify the encoding='utf-8' parameter when opening the file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question