我需要從SUDS
模塊擴展類Client
...比如我有這個簡單的代碼工作正常如何在Python中正確地擴展類以及使用父類?
client = Client(wsdl, username = USERNAME, password = PASSWORD, headers = {'Content-Type': 'application/soap+xml'}, plugins = [VapixHelper()])
rules = client.service.GetActionRules()
,所以我需要添加該類一些額外的方法,所以我儘量去做像這樣:
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很好的一個,謝謝...可能你可以提供一些信息,當需要調用父類時,'super(Vapix,self)'和'self'之間的區別在哪裏? – Kin
你可能想要閱讀http://stackoverflow.com/questions/576169/understanding-python-super-and-init-methods – icedtrees