【发布时间】:2018-08-13 18:48:18
【问题描述】:
Windows 上的默认控制台编码是什么?有时它似乎是 ANSI 编码 (CP-1252),有时它是由@987654323 给出的OEM 编码(西欧默认为CP-850) @ 命令。
-
命令行参数和环境变量触发ANSI编码(
é= 0xe9):> chcp 850 Active code page: 850 > python -c "print 'é'" Ú > python -c "print '\x82'" é > python -c "print '\xe9'" Ú > $env:foobar="é"; python -c "import os; print os.getenv('foobar')" Ú > chcp 1252 Active code page: 1252 > python -c "print 'é'" é > python -c "print '\x82'" , > python -c "print '\xe9'" é > $env:foobar="é"; python -c "import os; print os.getenv('foobar')" é -
Python 控制台 和 标准输入 触发 OEM 编码(
é= 0x82 如果 OEM 编码是 CP-850,é= 0xe9 如果 OEM 编码是 CP-1252):> chcp 850 Active code page: 850 > python >>> print 'é' é >>> print '\x82' é >>> print '\xe9' Ú > python -c "print raw_input()" é é > chcp 1252 Active code page: 1252 > python >>> print 'é' é >>> print '\x82' , >>> print '\xe9' é > python -c "print raw_input()" é é
注意。 – 在这些示例中,我在 Windows 10 上使用了 Powershell 5.1 和 CPython 2.7.14。
【问题讨论】:
标签: python python-2.7 character-encoding windows-console