import urllib2
from BeautifulSoup import BeautifulSoup
page = urllib2.urlopen('http://www.leeon.me');
soup = BeautifulSoup(page,fromEncoding="gb18030")
print soup.originalEncoding
print soup.prettify()
如果中文页面编码是gb2312,gb[......]
import urllib2
from BeautifulSoup import BeautifulSoup
page = urllib2.urlopen('http://www.leeon.me');
soup = BeautifulSoup(page,fromEncoding="gb18030")
print soup.originalEncoding
print soup.prettify()
如果中文页面编码是gb2312,gb[......]
现在的需求是,有若干个List,假设2个:
[1, 3, 5]
[4, 6]
我们要输出(1, 4), (1, 6), (3, 4), (3, 6), (5, 4), (5, 6)
Python中直接提供了笛卡尔乘积,很给力:
a = [1, 3, 5]
b = [4, 6]
import itertools
for x in itertools.product(a, b):
print x
(1, 4)
(1, 6)
(3, 4)
(3, 6)
([......]
先说下同步原语。
我们假设有两个信号量full(表示slots中有货),empty(表示slots中有空闲)
生产者:
producer:
wait(empty)
mutex_lock
put an item
mutex_unlock
signal(full)
消费者:
consumer:
wait(full)
mutex_lock
get an item
mutex_unlock
signal(empty)
上述同[......]