这让我发疯。.我正在尝试使用'é'char来复制字典,并且使用Python 3将我扔掉了。
from pprint import pprint
knights = {'gallahad': 'the pure', 'robin': 'the bravé'}
pprint (knights)
Run Code Online (Sandbox Code Playgroud)
错误
File "/data/prod_envs/pythons/python36/lib/python3.6/pprint.py", line 176, in _format
stream.write(rep)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 43: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
我阅读了Python ASCII文档,但似乎没有解决此问题的快速方法,除了将dict拆开,然后通过'.encode'将有问题的值重写为ASCII值,然后重新组装dict再次
我有什么办法可以在不拆开字典的情况下打印出来?
谢谢 !