[python]Windows 下的 ANSI 编码
Windows 下用记事本保存文件时有个 ANSI 编码,那么如何用 python 保存一个 ANSI 编码的文件呢?
python 中使用 mbcs
编码(Windows only)表示 ANSI:
with open('hello.txt', 'w') as f: f.write(u'你好'.encode('mbcs'))
执行上面的代码,就可以创建一个 ANSI 编码的文件。
ANSI == Windows 本地编码
在简体中文 Windows 系统中:ansi == gbk :
>>> u'你好'.encode('mbcs') '\xc4\xe3\xba\xc3 ...