python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128),python没办法处理非ascii编码的,此时需要自己设置python的默认编码,一般设置为utf8的编码格式。

import sys

reload(sys)

sys.setdefaultencoding('utf8')

python2中reload(sys)后设置编码的更多相关文章

  1. python为什么需要reload(sys)后设置编码

    python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: 'ascii' codec can't deco ...

  2. reload(sys)后print失效问题解决

    python版本: python2.7.6 #查看python默认编码格式 >>> import sys >>> print sys.getdefaultencod ...

  3. 关于Python IDLE reload(sys)后无法正常执行命令的原因

    转载自:http://blog.csdn.net/kxcfzyk/article/details/41414247?utm_source=tuicool&utm_medium=referral ...

  4. python中reload(sys)作用

    python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报错UnicodeDecodeError: 'ascii' codec can't decode ...

  5. python reload(sys) 后无法输出

    重新加载sys后,在idle里无法输出内容.出现这种情况,需要将sys的三个变量重新定义. 在重新载入sys之前,为三个变量赋值 a,b,c = sys.studin,sys.studout,sys. ...

  6. Python中的字符串与字符编码

    本节内容: 前言 相关概念 Python中的默认编码 Python2与Python3中对字符串的支持 字符编码转换 一.前言 Python中的字符编码是个老生常谈的话题,同行们都写过很多这方面的文章. ...

  7. 【转】Python中的字符串与字符编码

    [转]Python中的字符串与字符编码 本节内容: 前言 相关概念 Python中的默认编码 Python2与Python3中对字符串的支持 字符编码转换 一.前言 Python中的字符编码是个老生常 ...

  8. python2 中 unicode 和 str 之间的转换及与python3 str 的区别

    在python2中字符串分为unicode 和 str 类型 Str To Unicode 使用decode(), 解码 Unicode To Str 使用encode(), 编码 返回数据给前端时需 ...

  9. python 中的reload(sys)

    import sys  reload(sys)  sys.setdefaultencoding('utf-8') #python2中的使用方法 #重新载入 sys 模块,并设置默认编码为 utf8 & ...

随机推荐

  1. solidity高级理论(三):时间单位与view

    solidity高级理论(三):时间单位与view 关键字:时间单位.view.Gas优化 solidity使用自己的本地时间单位 变量 now 将返回当前的unix时间戳(自1970年1月1日以来经 ...

  2. Python常用的数据类型转换

    在实际开发中.经常要根据需求来转变一些变量的类型. 需要用到以下函数:

  3. 安装Jenkins getting started卡住

    前言 jenkins版本:2.32.3 操作系统:windows 卡住信息 如果在安装jenkins时卡在getting startted的界面,如下所示 解决方法 1.打开 运行  输入 servi ...

  4. java基础编程练习

    1.编写程序实现对给定的 4 个整数从大到小的顺序排列. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ...

  5. C# → 数据库

    Database: public static class dbconnection{ static string cons = "data source = (local) ;initia ...

  6. 【C编程基础】C程序常用函数

    基础知识 1.const const 修饰的数据类型是指常类型,常类型的变量或对象的值是不能被更新的. ; 或 ; //在定义该const变量时,通常需要对它进行初始化,因为以后就没有机会再改变它了 ...

  7. sftpdrive mtputty

    https://blog.csdn.net/junli_chen/article/details/77527250?locationNum=2&fps=1

  8. ubuntu 安装 GCC 和 G++ C++ 开发环境

    1.先安装 :sudo apt-get install build-essential 2.查看 gcc 版本 然后安装 统一版本的 g++ gcc --version gcc (Ubuntu/Lin ...

  9. 自适应:用JS做的自适应,是最差的自适应,记页面刷新前后尺寸变化

    今天遇到一个硬茬,我在使用weui重构一个页面时,出现一个问题:路由进入页面时,页面内容尺寸硬是会变大,刷新后又恢复正常: 项目背景:一个使用react-starter-kit构建的B端SPA项目 上 ...

  10. 解决y7000笔记本ubuntu下wifi无法连接问题

    查看wifi与蓝牙硬件开关,发现ideapad的硬件模块都是关闭的 rfkill list all 打开终端 输入 sudo gedit /etc/rc.local 写入以下内容 进行保存 #!/bi ...