假设我们有一个实例化
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)寻找self,host。我没有看到自己作为论点被传入。
然后在PiMixedClient中,因为PiHttpClient扩展了PiMixedClient,那么它的主机和self应该和PiMixedClient一样
然后gpio = NativeGPIO(客户端)再次在NativeGPIO _ init (自我,客户端)的 init 内部,从我不需要的调用函数供给自己?
所以当扩展到最低级别它变成RESTAPI基类时,它的sendRequest方法来自客户端,它来自PiMixedClient类的sendRequest?
答案 0 :(得分:0)
但实际上,看看python文档,它们非常好。