PyCharm 不显示西里尔文

PyCharm does not display Cyrillic

提问人:Alex 提问时间:1/30/2023 更新时间:2/1/2023 访问量:133

问:

帮助解决问题: 任务如下 - 将数据库模型保存在固定结构中。我使用终端(python manage.py dumpdata ... Json 文件已创建,但不显示西里尔文。UTF-8 编码,请帮忙。在此处输入图像描述 在此处输入图像描述

我尝试在设置中更改编码类型,我尝试手动重写json文件

json python-3.x 编码 utf-8 pycharm

评论

0赞 JosefZ 1/30/2023
你面对一个 mojibake 案例(从你的图片中推断出的例子):返回 .请不要在最小的可重现示例中使用代码/数据/错误的图像。在可能的情况下,复制实际文本,将其粘贴到问题中,然后将其格式化为代码。'╬фхцфр ═ютшэъш'.encode( 'cp866').decode( 'cp1251')Одежда Новинки

答:

0赞 Alex 2/1/2023 #1
import json


file = 
r'C:\Programming\python_django\store\products\fixtures\category.json'
file_2 = 
r'C:\Programming\python_django\store\products\fixtures\category.json'

with open(file, 'rb') as open_file:
    data = json.load(open_file)
    with open(file_2, 'w') as write_file:
        write_file.write(json.dumps(data, ensure_ascii=False,
                                    indent=0,

                                    separators=(',',  ': 
                                   ')).encode('cp866').decode('cp1251'))

评论

0赞 Community 2/3/2023
正如目前所写的那样,你的答案尚不清楚。请编辑以添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。您可以在帮助中心找到有关如何写出好答案的更多信息。