随笔分类 - 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"...
阅读全文
摘要: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
阅读全文
摘要:http://blog.csdn.net/vileboy/article/details/672772
阅读全文
摘要:http://stackoverflow.com/questions/739654/understanding-python-decorators用装饰器生成HTML代码,例如:@makebold@makeitalicdef say(): return "Hello"生成:Hello
阅读全文