2006-10-10 21:53:33| 分类: lang_python | 标签: |举报 |字号大中小 订阅
# -- static method --可以认为,static method 就是我们平常的静态函数。而 class method 会自动帮你传入一个当前 class 类型,类似 instance 自动帮你传一个 self 查不多。
class foobar(object):
def foo():
print "static"
foo = staticmethod(foo)
f = foobar()
f.foo()
foobar.foo()
# ---
# -- class method --
class foobar(object):
def foo(cls):
print "class", cls
foo = classmethod(foo)
f = foobar()
f.foo()
foobar.foo()
# -- static method --
class foobar(object):
@staticmethod
def foo():
print "static"
评论