by shigemk2

当面は技術的なことしか書かない

must be called with Foo instance as first argument (got nothing instead)

2006-09-11 - pythonco(ぱいそんこ)の日記

class Foo:
    @classmethod
    def bar(self):
        print 'fuga-'

Foo.bar() # fuga-

class Foo:
    def bar(self):
        print 'fuga-'
    bar = classmethod(bar)

Foo.bar() # fuga-

class Foo:
    def bar(self):
        print 'fuga-'

# インスタンスメソッドはインスタンスを生成すれば呼び出せるが、クラスに対しては呼び出せない
Foo().bar() # fuga-
Foo.bar() # TypeError: unbound method bar() must be called with Foo instance as first argument (got nothing instead)

クラス(class) « python練習帳