Python 实例不可调用';元组';对象
需要调用Python 实例不可调用';元组';对象,python,camera,raspberry-pi,raspbian,Python,Camera,Raspberry Pi,Raspbian,需要调用Camera类中的capture()方法(省略)。只需在脚本中运行代码即可正常运行: # import io, picamera, etc.. with picamera.PiCamera() as camera: camera.resolution(self.camwidth, self.camheight) camera.start_preview() 当我尝试使其面向对象时,它失败了: class Camera(object): def __init__(
Camera
类中的capture()
方法(省略)。只需在脚本中运行代码即可正常运行:
# import io, picamera, etc..
with picamera.PiCamera() as camera:
camera.resolution(self.camwidth, self.camheight)
camera.start_preview()
当我尝试使其面向对象时,它失败了:
class Camera(object):
def __init__(self, cam_width, cam_height):
self.camwidth = cam_width
self.camheight = cam_height
with picamera.PiCamera() as camera:
camera.resolution(self.camwidth, self.camheight)
camera.start_preview()
time.sleep(2)
camera = Camera(32, 24)
错误如下所示:
File "ActionScript.py", line 23, in <module> camera = Camera(32, 24)
File "ActionScript.py", line 13, in __init__ camera.resolution(self.camwidth,self.camheight)
TypeError: 'tuple' object is not callable
。。从物体内部看,它似乎有问题。Always“tuple对象不可调用。我还尝试将
\uuuu init\uuuu()
设置为仅注册32x24值,并使用cameraSetup()
方法在调用camera.cameraSetup()后以相同的结果运行安装程序
camera.resolution是一个元组。这意味着它是一个数组数据结构,不能通过实例化来修改。你肯定也不能像函数一样调用它。相反,将它指向一个新的元组
camera.resolution = (self.camwidth, self.camheight)
资料来源:
camera.resolution = (self.camwidth, self.camheight)