Windows 7和Python 3.5.2
使用sys.stdout.write()打印包含Unicode的字符串
如果我执行“ python my.py infile”,则会得到:
'charmap' codec can't encode characters in position 45739-45740: character maps to <undefined>
如果我执行“ python my.py infile> outfile”,将stdout重定向到文件,则可以正常工作。
直到我做完为止,我一直都遇到相同的错误:
outStr = outStr.encode("utf-8").decode()
我还需要过滤掉一些额外的'\ r'字符。
始终如一的正确方法是什么?