Python, Unicode, and the Windows console

前端 未结 13 2115
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 04:38

When I try to print a Unicode string in a Windows console, I get a UnicodeEncodeError: \'charmap\' codec can\'t encode character .... error. I assume this is b

13条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 05:17

    For Python 2 try:

    print unicode(string, 'unicode-escape')
    

    For Python 3 try:

    import os
    string = "002 Could've Would've Should've"
    os.system('echo ' + string)
    

    Or try win-unicode-console:

    pip install win-unicode-console
    py -mrun your_script.py
    

提交回复
热议问题