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
相关文档:
转帖:
http://blog.csdn.net/wyingquan/archive/2008/12/20/3561094.aspx
用python自带的binascii模块计算字符串的校验码,出来的是负值,与用c写的程序得出的校验码不一样,所以就研究了一下。发现别人用的python3.0版本binascii模块计算出的crc32校验码是我想要的,没办法只好自己用python实现一下crc32的算法了。发 ......
Python内建异常体系结构
BaseException
+-- SystemExit
+-- KeyboardInterrupt
+-- GeneratorExit
+-- Exception
+-- StopIteration
+-- StandardError
| +-- BufferError
| +-- ArithmeticError
| | +-- FloatingPointError
| | +-- OverflowError
| ......
Memcached
是danga.com(运营LiveJournal的技术团队)开发的一套分布式内存对象缓存系统,用于在动态系统中减少数据库负载,提升性能。
网上有很多讲到Memcached For Linux的安装教程,但是Memcached For Win32 and Python的就甚少,偶尔google找到一篇
比较相近的英文教程,觉得 ......
总结下,Python 下载网页的几种方法
1
fd = urllib2.urlopen(url_link)
data = fd.read()
这是最简洁的一种,当然也是Get的方法
2
通过GET的方法
def GetHtmlSource(url):
try:
htmSource = ''
&nb ......
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 ......