def get_recursively(search_dict, field):
"""
Takes a dict with nested lists and dicts,
and searches all dicts for a key of the field
provided.
"""
fields_found = []
for key, value in search_dict.iteritems():[......]
def get_recursively(search_dict, field):
"""
Takes a dict with nested lists and dicts,
and searches all dicts for a key of the field
provided.
"""
fields_found = []
for key, value in search_dict.iteritems():[......]
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
print(s.getsockname()[0])
s.close()
备注:这个IP有可能被墙,可以换一个国内的,呵呵。。
如果是NAT出口的,显示的是NAT的IP地址。[......]
转载自:http://www.tuicool.com/articles/vIRryi
product 笛卡尔积
permutations 排列
combinations 组合,没有重复
combinations_with_replacement 组合,有重复
>>> import itertools
>>> for i in itertools.product('ABCD', repeat = 2):
... print[......]
标题虽然说是线程,其实gevent用的是“greenlet”,可能翻译成"微线程"更合适一些。
1、线程池
import time
import gevent
from gevent.threadpool import ThreadPool
def my_func(text, num):
print text, num
pool = ThreadPool(100)
start = time.time()
for i in xrange(100000):[......]