0
讓
我們說我們有一個實例瞭解Python類和基礎類
client = PiHttpClient("192.168.1.234")
# RPi native GPIO
gpio = NativeGPIO(client)
gpio.setFunction(25, "out")
state = True
而且從clients.py代碼我有
class PiMixedClient():
def __init__(self, host, port=8000, coap=5683):
def sendRequest(self, method, uri):
class PiHttpClient(PiMixedClient):
def __init__(self, host, port=8000):
PiMixedClient.__init__(self, host, port, -1)
class NativeGPIO(GPIO):
def __init__(self, client):
RESTAPI.__init__(self, client, "/GPIO")
class GPIO(Device):
def __init__(self, client, name):
Device.__init__(self, client, name, "digital")
def getFunction(self, channel):
return self.sendRequest("GET", "/%d/function" % channel)
def setFunction(self, channel, func):
return self.sendRequest("POST", "/%d/function/%s" % (channel, func))
class Device(RESTAPI):
def __init__(self, client, name, category):
RESTAPI.__init__(self, client, "/devices/" + name + "/" + category)
class RESTAPI():
def __init__(self, client, path):
self.client = client
self.path = path
def sendRequest(self, method, path):
return self.client.sendRequest(method, self.path + path)
所以,從上面的時候它PiHttpClient(「192.168.1.234」)主機=「192.168.1.234」,對不對?但是init(self,host,port = 8000)尋找自己,主機。我沒有看到自我被作爲論點傳入。
然後內部PiMixedClient,因爲PiHttpClient延伸PiMixedClient,那麼它的主機和自我應儘可能相同PiMixedClient
然後GPIO = NativeGPIO(客戶端)再次INIT NativeGPIO的 _ 內部初始化 (自我,客戶),從調用函數我不需要提供自我?
所以當擴展到最低級時它變成了RESTAPI基類,它的sendRequest方法來自客戶端,它來自PiMixedClient類的sendRequest?
請更正您的縮進.. – adil