Python 中的字符编码
1、str类型可以理解为一个二进制block,或multibyte
2、multibyte_str.decode("<multibyte_encode_method>") -> unicode
3、unicode_str.encode("<multibyte_encode_method>") -> multibyte_str(binary block)
4、unicode_str 的操作参数也应为unicode,如:unicode_str.find("样本".decode("utf-8"))
5、代码里的u前缀会自动生成unicode字符串(它跟据源码首部的#coding:*** 段来决定应该怎样由multibyte生成unicode)
6、python 的print将输出binary block给console,colsole将用系统的multibyte_encode_method为显示这些binary block
REF
http://blog.sina.com.cn/s/blog_620c017e0100erh8.html
相关文档:
当python中间处理非ASCII编码时,经常会出现如下错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128)
0x??是超出128的数字,python在默认的情况下认为语言的编码是ascii编码,所以无法处理其他编码,需要设置python的默认编码为所需要的编码。
一个解决的方案是 ......
def retrive_emails(pop3_server, user_name, passwd, server_port):
#POP3
pop_client = poplib.POP3(pop3_server, port=server_port)
pop_client.user(user_name)
pop_client.pass_(passwd)
......
#filename Seek.py
import unicodedata
import sys
import os
class Seek():
"""
功能:查找中文,并替换成指定字符或字符串
使用方法:python脚本用法
参数说明:
-d& ......
import urllib2
import time
import socket
from datetime import datetime
from thread_pool import *
def main():
url_list = {"sina":"http://www.sina.com.cn",
"sohu":"http://www.sohu.com",
"yahoo":"http://www.yahoo.com",
"xiaonei":"http://www.x ......