0
我使用RaspberryPi3和Python来远程控制其他RPI的GPIO。如何继承Class属性Python
我创建了一个类来初始化所有小童连接和销:
class relay(pigpio.pi):
def __init__(self,ip_addr):
pigpio.pi.__init__(self)
self.GPIO=[4,5,6,12]
self.rpi=pigpio.pi(ip_addr)
for t in range(len(self.GPIO)):
self.rpi.write(self.GPIO[t],0)
def switch_state(self,i,state):
self.rpi.write(self.GPIO[i],state)
pi_1=relay('192.168.2.112') # creating first Rpi link
pi_2=relay('192.168.2.113') # creating second Rpi link
x=0
pi_1.switch_state(x,0)
我怎么能继承pigpio
模块的属性为relay
?为了不产生switch_state
像我一样,但使用read
,write
多属于pigpio
您只能从类继承,而不能从模块继承。 – Goyo