python编码问题1
2015-12-16 00:00
483 查看
在windows的cmd控制台的打印(编码GBK):
在设置了默认编码为UTF8的pycharm的控制台:
>>> print repr('哈') '\xb9\xfe' >>> ('\xb9\xfe').decode('gbk') u'\u54c8' >>> ('\xb9\xfe').decode('gb2312') u'\u54c8' >>> ('\xb9\xfe').decode('gbk').encode('utf8') '\xe5\x93\x88' >>> ('\xb9\xfe').decode('gb2312').encode('utf8') '\xe5\x93\x88' >>> '\xb9\xfe'=='哈' True >>> '\xe5\x93\x88'=='哈' False #查看本机编码方式 >>> print sys.getdefaultencoding() ascii >>> print sys.getfilesystemencoding() mbcs #python文档对mbcs的解释:Windows only: Encode operand according to the ANSI codepage (CP_ACP) #报错 >>> print ('哈').decode('utf8') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\Lib\encodings\utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xb9 in position 0: invalid s tart byte
在设置了默认编码为UTF8的pycharm的控制台:
In[2]: print repr("哈") '\xe5\x93\x88'
相关文章推荐
- 【Python 第9课】random
- 【Python 第10课】 变量2
- 【Python 第11课】 逻辑判断
- 【Python 第8课】while
- leetcode Longest Valid Parentheses python
- [Python标准库]re——正则表达式[五]
- python version 2.7 required,which was not found in the registry
- python核心编程-模块
- Python学习之--socket
- Python程序用pyinstaller打包成exe文件
- threadpool——python线程池
- argparse——python命令行解析
- python简单socket
- 安装 MySQLdb 出现 Python version 2.7 required, which was not found in the registry
- (转)Vim的Python编辑器详细配置过程 (Based on Ubuntu 12.04 LTS)
- Python拾遗(三)常用的数据类型
- 利用Python数据处理进行公交车到站时间预测(一)
- day8 python学习随笔(下)
- 《利用python进行数据分析》读书笔记--第九章 数据聚合与分组运算(二)
- Python-MySQL summary