实例不可调用'元组'对象

时间:2014-05-12 13:10:54

标签: python camera raspberry-pi raspbian

需要在capture()类中调用Camera方法(省略)。只需在脚本中运行代码即可运行它:

# 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

我尝试了不同的方法,但行:

camera.resolution(self.camwidth, self.camheight)

..似乎是从对象内部出现问题的那个。始终“元组对象不可调用。我也尝试将__init__()设置为仅注册32x24值和cameraSetup()方法,以便在调用camera.cameraSetup()

1 个答案:

答案 0 :(得分:1)

camera.resolution是一个元组。这意味着它的数组数据结构在实例化之后无法修改。你绝对不能把它称为功能。相反,将它指向一个新的元组。

camera.resolution = (self.camwidth, self.camheight)

来源:http://picamera.readthedocs.org/en/latest/recipes1.html