Python 为什么调用方法时有两个参数?
我写了一个程序,但不使用self,现在我试图用self重写它。 我几乎到处都放了一些自我,但我有一个给定论点的问题。 首先,我创建一个类:Python 为什么调用方法时有两个参数?,python,arguments,self,Python,Arguments,Self,我写了一个程序,但不使用self,现在我试图用self重写它。 我几乎到处都放了一些自我,但我有一个给定论点的问题。 首先,我创建一个类: class photo(): def _init_cam(self,x,y): self.camera = PiCamera() self.camera.resolution = (x,y) self.camera.start_preview() sleep(2) pri
class photo():
def _init_cam(self,x,y):
self.camera = PiCamera()
self.camera.resolution = (x,y)
self.camera.start_preview()
sleep(2)
print("camera init")
return self.camera
给我带来问题的方法是:
def capture_image(self):
global wait # Empeche le if de ce déclencher avant la fin de la fonction
wait = False
# Get the current date as the timestamp to generate unique file names.
self.date = datetime.datetime.now().strftime('%m-%d-%Y_%H.%M.%S')
# Add date as timestamp on the generated files.
#camera.annotate_text = date
# Capture an image as the thumbnail.
self.camera.capture('/home/pi/Pictures/' + self.date + '.jpg')
print("\r\nImage Captured! \r\n")
wait = True
在我的主页中,我创建了我的对象:
camera =photo()
camera._init_cam(3280,2464)
然后我调用我的方法:
GPIO.add_event_detect(23,GPIO.FALLING,callback = camera.capture_image, bouncetime = 300)
错误:
TypeError:capture_image()接受1个位置参数,但给出了2个
我不知道它为什么会给出第二个论点,也不知道是否有任何方法可以看出这个论点是什么
谢谢。根据线程回调部分中的示例,回调被传递一个他们命名为
通道的参数。该库的文档似乎很少,所以我无法告诉您参数的含义。大概是GPIO
在调用回调函数时将参数传递给回调函数…?谢谢,它似乎给了我频道号。是的,就是这样。谢谢