2011-11-15 10 views

答えて

37

最良の説明は、ソースコードそのものであってもよい。

class classonlymethod(classmethod): 
    def __get__(self, instance, owner): 
     if instance is not None: 
      raise AttributeError("This method is available only on the view class.") 
     return super(classonlymethod, self).__get__(instance, owner) 

差がclassmethodがクラスにそれを呼び出すのと同じ効果を有する、インスタンス上で呼び出すことができることであるが、classonlymethodのみ缶クラスで呼び出される。

+0

したがって、 'classonlymethod'と' staticmethod'の唯一の違いは署名にありますか? – arijeet

+1

@ redskins80いいえ、違いはクラスインスタンスで 'classonlymethod'を使用できないことです。 – dotslash

関連する問題