cmd终端输出中文乱码

67 阅读1分钟

解决办法:

import locale

print("中文".encode(locale.getpreferredencoding()))
locale.getpreferredencoding() #为打开本地文件时使用的解码器
sys.getdefaultencoding()      #为在python程序内,在字节序列和字符串之间转换时使用’‘utf-8’’
sys.getfilesystemencoding()   #为打开文件名称编码器