7
@staticmethod 데코레이터를 사용하여 클래스 '__call__ 메소드를 정적으로 만들 수없는 이유는 무엇입니까?@staticmethod로 __call__을 장식하기
class Foo(object):
@staticmethod
def bar():
return 'bar'
@staticmethod
def __call__():
return '__call__'
print Foo.bar()
print Foo()
출력
bar
<__main__.Foo object at 0x7fabf93c89d0>
하지만 출력
당신은 메타 클래스에
__call__
를 오버라이드 (override) 할 필요가
bar
__call__
감사합니다! 그것은 나를 위해 그것을 깨끗하게한다. 'Meta .__ call __()'->'Foo .__ new __()'->'Foo .__ init __()'의 의미는 무엇입니까? 화살표는 "전화"를 의미합니까? – fragapanagos
@fragapanagos 클래스가 인스턴스화 될 때 파이썬이 따르는 순서입니다. 참조 : http://ideone.com/4gxeiN –