摘要: line是模板中一行的内容,类似: {{x}}testinfo{{x+10}} x=10时,模板输出: 10testinfo20 阅读全文
posted @ 2017-02-22 20:28 鸪斑兔 阅读(432) 评论(0) 推荐(0) 编辑
摘要: >>> hobbies = ['software'] >>> ('notchecked', 'checked')['software' in hobbies] 'checked' >>> 'checked' if 'software' in hobbies else 'notchecked' 'checked' >>> hobbies = ['xxx'] >& 阅读全文
posted @ 2017-02-10 16:36 鸪斑兔 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 一个带有参数的装饰器的例子: bottle.py中自动转换参数类型的装饰器: 阅读全文
posted @ 2017-02-06 10:24 鸪斑兔 阅读(1803) 评论(0) 推荐(0) 编辑
摘要: import re class SimpleTemplate(object): re_block = re.compile(r'^\s*%\s*((if|elif|else|try|except|finally|for|while|with).*:)\s*$') re_end = re.compile(r'^\s*%\s*end(.*?)\s*$') re_cod... 阅读全文
posted @ 2017-02-04 10:35 鸪斑兔 阅读(240) 评论(0) 推荐(0) 编辑
摘要: # Now search regexp routes # ROUTES_REGEXP是一个字典,键是请求方法,值是[路由, 处理函数]的列表 # 例如:{"GET", [[路由1, 处理函数1], [路由2, 处理函数2]]} routes = ROUTES_REGEXP.get(method,[]) for i in xrange(len(routes)): match = route... 阅读全文
posted @ 2017-01-26 11:14 鸪斑兔 阅读(244) 评论(0) 推荐(0) 编辑
摘要: # Routing def compile_route(route): """ Compiles a route string and returns a precompiled RegexObject. Routes may contain regular expressions with named groups to support url parameters. ... 阅读全文
posted @ 2017-01-25 17:35 鸪斑兔 阅读(560) 评论(0) 推荐(0) 编辑
摘要: 目前看到的最详细最全面的解释: http://www.snailbook.com/faq/background-jobs.auto.html SSH Frequently Asked Questions Sometimes my SSH connection hangs when exiting — 阅读全文
posted @ 2016-12-28 14:05 鸪斑兔 阅读(1036) 评论(0) 推荐(0) 编辑
摘要: class Test(object): def __get__(self, instance, type=None): """ 只让类访问, 而不让类的实例来访问。 具体是靠 __get__(self, instance, type=None) 方法来实现来的: 第二个参数 instance, 当 class.attr 的时... 阅读全文
posted @ 2016-11-28 09:47 鸪斑兔 阅读(237) 评论(0) 推荐(0) 编辑
摘要: # -*- coding: utf-8 -*-import osimport subprocessimport signalimport pwdimport sysclass MockLogger(object): '''模拟日志类。方便单元测试。''' def __init__(sel... 阅读全文
posted @ 2014-09-17 09:54 鸪斑兔 阅读(5005) 评论(1) 推荐(1) 编辑
摘要: # -*- coding: utf8 -*-import logging# 创建一个loggerlogger = logging.getLogger('mylogger')logger.setLevel(logging.DEBUG)# 创建一个handler,用于写入日志文件fh = logging... 阅读全文
posted @ 2014-09-16 09:16 鸪斑兔 阅读(1268) 评论(0) 推荐(0) 编辑