下面的程序非常简单。它启动运行Windows port of the Unix utility less的子进程。你知道吗
import subprocess
subprocess.run('less.exe', input='Macarrão é uma delícia.', encoding='utf-8')
输入为:
Macarrão é uma delícia.
不过,结果是:
Macarrão é uma delícia.
对此有何解释?我注意到在运行python代码之前运行chcp 65001
可以解决这个问题,但是查看related post我不确定这是最好的方法。引用公认答案:
chcp 65001 is very dangerous. Unless a program was specially designed to work around defects in the Windows’ API (or uses a C runtime library which has these workarounds), it would not work reliably. Win8 fixes ½ of these problems with
cp65001
, but the rest is still applicable to Win10.
我正在Windows1064位上运行Python3.7.0。你知道吗
正如eryk所建议的,一种方法是将控制台代码页设置为UTF-8,然后运行更少.exe并将代码页设置回原来的状态。你知道吗
相关问题 更多 >
编程相关推荐