惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
The Register - Security
The Register - Security
量子位
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
MyScale Blog
MyScale Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
Jina AI
Jina AI
博客园 - 【当耐特】
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
G
GRAHAM CLULEY
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
有赞技术团队
有赞技术团队
T
Tor Project blog
H
Hacker News: Front Page
A
Arctic Wolf
NISL@THU
NISL@THU
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
V
V2EX
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
I
InfoQ
D
Docker
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42

博客园 - jingleguo

[zz]软件测试专业术语 word分栏时脚注强制分页问题解决 安装JDK和TOMCAT并配置环境变量的过程 - jingleguo - 博客园 Thinkpad鼠标在Chrome中无法使用滚轮 [zz]第五套人民币发行冠号 SourceForge镜像 How Can You Buy or Sell The Sky?[zz] china-pub返回的错误网页 - jingleguo - 博客园 X61 T61 休眠后自动重启与耗电问题 自题 'You've got to find what you love,' Jobs says 使用VC向Windows发送消息代码示例 百度千万别做邮箱 察传 赋得自君之出矣 用逻辑来骗MM和在论坛上骗钱 Google 的午餐 Java使用Scream流读入并输出文件示例 集句
Python设置默认语言编码
jingleguo · 2008-06-02 · via 博客园 - jingleguo

当python中间处理非ASCII编码时,经常会出现如下错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128)
0x??是超出128的数字,python在默认的情况下认为语言的编码是ascii编码,所以无法处理其他编码,需要设置python的默认编码为所需要的编码。
一个解决的方案是在代码中添加:

import sys

reload(sys)
sys.setdefaultencoding('gb2312')

另一个方案是在python的Lib\site-packages文件夹下新建一个sitecustomize.py
文件(sitecustomize.py is a special script; Python will try to import it on startup, so any code in it will be run automatically.),输入:

import sys
sys.setdefaultencoding('gb2312')

这样就能够自动的设置编码了。
ps:
1. utf8的编码是:utf-8

2. 测试已经成功的方法:
>>> import sys
>>> sys.getdefaultencoding()