随笔分类 -  Python

摘要:class Singleton(type): def __call__(cls, *args, **kwargs): print "Singleton call" if not hasattr(cls, 'instance'): cls.instance = super(Singleton, cls).__call__(*args, **kwargs) return cls.instance def __new__(cls, name, bases, dct): print "Singleton new"... 阅读全文
posted @ 2013-02-05 09:29 鸪斑兔 阅读(1886) 评论(1) 推荐(0) 编辑
摘要:class MyClass(BaseClass): def __new__(cls, *args, **kwargs): return super(MyClass, cls).__new__(cls, *args, **kwargs)super并不是一个函数,而是一个类名,形如super(B, cls)事实上调用了super类的初始化函数,产生了一个super对象。Python Manuals上介绍:super(type[, object-or-type]) Return a proxy object that delegates method calls to a parent or sib 阅读全文
posted @ 2013-02-01 11:31 鸪斑兔 阅读(14829) 评论(1) 推荐(0) 编辑
摘要:http://blog.csdn.net/vileboy/article/details/672772 阅读全文
posted @ 2013-01-28 14:50 鸪斑兔 阅读(169) 评论(0) 推荐(0) 编辑
摘要:http://stackoverflow.com/questions/739654/understanding-python-decorators用装饰器生成HTML代码,例如:@makebold@makeitalicdef say(): return "Hello"生成:Hello 阅读全文
posted @ 2013-01-25 11:17 鸪斑兔 阅读(179) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示