PyDeencodee手表

2024-06-25 05:56:36 发布

您现在位置:Python中文网/ 问答频道 /正文

版本包括:

  • PyCharm 2018.1.2(专业版)
  • Python 2.7版
  • Python 3.6版

你知道吗测试.py你知道吗

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import sys

print(sys.getdefaultencoding())
d = {'中文': '中文'}
print(d)

运行python test.py时,输出是

ascii
{u'\u4e2d\u6587': u'\u4e2d\u6587'}

但是当在Python2.7的调试器中watch调用它时,将引发UnicodeEncodeError。你知道吗

enter image description here

但是用Python3.6在Pycharm中调试它是正常的:

enter image description here


Tags: frompyimport版本sysunicodefutureutf