美文网首页
python在WIN下CMD运行中文乱码及python 2.x

python在WIN下CMD运行中文乱码及python 2.x

作者: Hobort | 来源:发表于2020-03-06 15:59 被阅读0次

D=raw_input(unicode('请输入三个数字,格式如:a,b,c\n','utf-8').encode('gb2312'))

网上搜索的方法中说,把CMD的编码格式改为UTF-8格式,命令介绍:

chcp65001#转换为utf-8代码页chcp936#转换为默认的gbk

一般CMD默认gbk,在CMD窗口中输入chcp 65001修改为utf-8

# -*- coding: UTF-8 -*-

content = "我是中文"

content_unicode = content.decode("utf-8")

content_gbk = content_unicode.encode("gbk")

print content_gbk

#!/usr/bin/python

# coding: utf-8

os_char='gb18030'

printu"直接打印Unicode"

printu"Unicode转换成GB18030".encode(os_char)

print"UTF-8中文转换到GB18030, 然后再打印".decode("utf-8").encode(os_char)

相关文章

网友评论

      本文标题: python在WIN下CMD运行中文乱码及python 2.x

      本文链接:https://www.haomeiwen.com/subject/iqetdxtx.html