는 super()
는 인수없이 호출 할 수 있습니다 :이 작업을하기 위해왜 Python 3.x의 super() 매직입니까? 파이썬 3.x의에서
class A(object):
def x(self):
print("Hey now")
class B(A):
def x(self):
super().x()
>>> B().x()
Hey now
가 일부 컴파일시의 마법이 수행, 하나 개 결과 어느 것을 다음 코드 (이는 super
super_
에 리 바인드) 실패
super_ = super
class A(object):
def x(self):
print("No flipping")
class B(A):
def x(self):
super_().x()
>>> B().x()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in x
RuntimeError: super(): __class__ cell not found
왜 입술에 super()
수없는 컴파일러의 도움없이 런타임시 수퍼 클래스를 olve 하시겠습니까? 이 행동 또는 그 근본적인 이유가 부주의 한 프로그래머를 물릴 수있는 실제적인 상황이 있습니까?
... 그리고 부차적 인 질문으로 파이썬에서 다른 이름으로 리바 인딩하여 기능을 손상시킬 수있는 다른 예제가 있습니까?
내가 아르 민을 할거야 (이 [한]에 설명을 http://lucumr.pocoo.org/2010/1/7/pros-and-cons-about-python-3 /)을 사용합니다. 이것은 또 다른 좋은 [게시물] (http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/) –
관련 : http://stackoverflow.com/q/36993577/674039 – wim