2014-03-03 2 views
0

의 그것을 그렇게되면 우리는 인스턴스를파이썬 클래스의 이해와 기본 클래스

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) 
  1. 있다고 가정 해 봅시다 PiHttpClient ("192.168.1.234") 호스트 = "192.168.1.234", 맞습니까? (self, host, port = 8000)은 자체 호스트를 찾습니다. 나는 자기가 논쟁으로 전달되는 것을 보지 못했다.

  2. 다음 PiMixedClient 내부 PiHttpClient가 PiMixedClient 연장하기 때문에, 그때 그 호스트와 자기

  3. 다음 = 다시 NativeGPIO (클라이언트)를 INIT NativeGPIO의 _ 내부 INIT을 GPIO PiMixedClient 같은과 같아야 (자기, 클라이언트), 호출 기능에서 나는 자기를 공급할 필요가 없다?

  4. 그래서 가장 낮은 레벨로 확장하면 RESTAPI 기본 클래스가되며 sendRequest 메소드는 PiMixedClient 클래스의 sendRequest?

+0

들여 쓰기를 수정하십시오. – adil

답변

0
  1. 예 - 파이썬 방법은 항상 첫 번째 인수로 자기를 얻을, 당신은 클래스에 docs를 살펴 할 수 있습니다.
  2. - 당신이 클래스 (당신이 init 메소드를 오버라이드 (override) 할 경우 수행)
의 인스턴스를 만드는 경우
  • 번호 당신은 수동으로 유의점 자체가 필요하지 않습니다

    하지만 실제로는 파이썬 문서를 살펴보세요. 꽤 좋습니다.

  • 관련 문제