나는 예를 들어 내가파이썬에서 클래스를 올바르게 확장하고 부모 클래스를 사용하는 방법은 무엇입니까?
client = Client(wsdl, username = USERNAME, password = PASSWORD, headers = {'Content-Type': 'application/soap+xml'}, plugins = [VapixHelper()])
rules = client.service.GetActionRules()
을 잘 작동 그래서 나는 그래서 그것을 수행하려고이 클래스에 대한 몇 가지 여분의 방법을 추가 할 필요가 간단한 코드를 ... SUDS
모듈에서 클래스 Client
을 확장 할 필요가 이 같은 :
class Vapix(Client):
def __init__(self, args):
globals().update(vars(args))
USERNAME, PASSWORD = user_data.split(':')
super(Vapix, self).__init__(wsdl, username = USERNAME, password = PASSWORD, headers = {'Content-Type': 'application/soap+xml'}, plugins = [VapixHelper()])
def setActionStatus(self, status):
print super(Vapix, self).service.GetActionRules()
그리고 내가 대신 결과이 오류를 얻을 :
Traceback (most recent call last):
File "vapix.py", line 42, in <module>
client.setActionStatus(True)
File "vapix.py", line 36, in setActionStatus
print super(Vapix, self).service.GetActionRules()
AttributeError: 'super' object has no attribute 'service'
그냥'self.service'를 사용하십시오. – BrenBarn
@BrenBarn nice, thanks ... 부모 클래스를 호출해야 할 때'super (Vapix, self)'와'self'의 차이점은 무엇인가? – Kin
http://stackoverflow.com/questions/576169/understanding-python-super-and-init-methods – icedtrees