摘要: 1.与同步模型的优势: 1.有大量的任务,一个时刻内至少有一个任务要运行 2.任务执行大量的I/O,同步模型会因为任务阻塞而浪费大量时间 3.任务之间相互独立,任务内部交互少.2.与同步模式客户端的差别: 1.异步模式会一次性与全部服务器完成连接,而不是同步模式那样一次连接一... 阅读全文
posted @ 2014-07-19 20:26 huangxiaohen 阅读(241) 评论(0) 推荐(0) 编辑
摘要: #coding:utf8try: import qrcodeexcept ImportError: qrcode = Noneclass MakeQr: def onUseQrcode(self, value): qr = qrcode.QRCode(version=1,... 阅读全文
posted @ 2014-07-16 11:58 huangxiaohen 阅读(603) 评论(0) 推荐(1) 编辑
摘要: #encoding=utf-8import randomfrom copy import copy def directInsertSort(seq): """ 直接插入排序 """ size = len(seq) for i in range(1,size): t... 阅读全文
posted @ 2014-07-15 20:25 huangxiaohen 阅读(474) 评论(0) 推荐(0) 编辑
摘要: import sys class Stats: def __init__(self, sequence): # sequence of numbers we will process # convert all items to floats for numeri... 阅读全文
posted @ 2014-07-15 20:22 huangxiaohen 阅读(59050) 评论(1) 推荐(0) 编辑
摘要: lambda表达式返回一个函数对象例子:func = lambda x,y:x+yfunc相当于下面这个函数def func(x,y): return x+y 注意def是语句而lambda是表达式下面这种情况下就只能用lambda而不能用def[(lambda x:x*x)(x) for x... 阅读全文
posted @ 2014-07-13 20:57 huangxiaohen 阅读(500) 评论(0) 推荐(0) 编辑
摘要: filter(function, sequence):对sequence中的item依次执行function(item),将执行结果为True的item组成一个List/String/Tuple(取决于sequence的类型)返回:>>> def f(x): return x % 2 != 0 an... 阅读全文
posted @ 2014-07-13 20:50 huangxiaohen 阅读(737) 评论(0) 推荐(0) 编辑
摘要: 1.求1~100以内的素数prime=filter(lambda x: not [x%i for i in range(2,x) if x%i==0], range(2,101))#列表推导,一行搞定.print prime2.求字符串子串s='hauifnefldmfp'[s[i:i+n] for... 阅读全文
posted @ 2014-07-12 20:35 huangxiaohen 阅读(308) 评论(0) 推荐(0) 编辑
摘要: list = [1,1,3,4,6,3,7] 1.for s in list: if list.count(s) >1: list.remove(s) 2.list2=[]for s in list: if s not in list2: list2.ap... 阅读全文
posted @ 2014-07-09 17:44 huangxiaohen 阅读(1518) 评论(0) 推荐(0) 编辑
摘要: 1.安装django-pagination2.将文件夹pagination复制到项目的根目录下3.修改settings: 1.将'pagination.middleware.PaginationMiddleware', 添加到MIDDLEWARE_CLASSES中。 2.app添加 'pagi... 阅读全文
posted @ 2014-07-05 17:22 huangxiaohen 阅读(280) 评论(0) 推荐(0) 编辑
摘要: python manage.py schemamigration youappname --initial # --initial在数据库创建models定义的表,以及South需要的south_migrationhistory表,另外会在youappname目录下面创建一个migratio... 阅读全文
posted @ 2014-06-30 11:20 huangxiaohen 阅读(329) 评论(0) 推荐(0) 编辑