Python TypeError:缺少2个必需的位置参数//如何修复它?
我有一个Python TypeError:缺少2个必需的位置参数//如何修复它?,python,python-3.x,anaconda,typeerror,Python,Python 3.x,Anaconda,Typeerror,我有一个TypeError:capture\u和\u decode()缺少两个必需的位置参数:“bitrange”和“axes” 我的代码是: def capture_and_decode(self, bitrange, axes): cam_width, cam_height = self.camera.resolution scr_range = self.display.displaywindow.resolution self.raw_images = numpy
TypeError:capture\u和\u decode()缺少两个必需的位置参数:“bitrange”和“axes”
我的代码是:
def capture_and_decode(self, bitrange, axes):
cam_width, cam_height = self.camera.resolution
scr_range = self.display.displaywindow.resolution
self.raw_images = numpy.empty((len(axes), cam_height, cam_width, bitrange))
for axis in axes:
for bits in range(0,bitrange):
stripe_width = cam_width // 2 ** (bits + 1)
print(stripe_width)
binary = numpy.fromiter(GrayCode(bits + 1).generate_gray(), dtype=numpy.int) % 2
vector = numpy.repeat(binary, stripe_width)
img = numpy.tile(vector, (cam_height, 1))
self.display.displaywindow.show(img)
time.sleep(0.25)
self.raw_images[axis, :, :, bits] = self.camera.capture()
错误在最后一行。您的代码如下所示:
obj.capture_and_decode()
第一个参数(self
)是为您提供的,但您需要考虑其他两个参数
如果它们是可选的,请将函数定义更改为包含默认值,例如:
def capture_and_decode(self, bitrange=10, axes=[])
您的
capture\u and_decode()
方法设计为接受两个位置参数;即位范围和轴。无论在何处调用此方法,都需要提供以下参数:
cam = CameraClass()
cam.capture_and_decode(500, 4) # or whatever the values should be.
您在哪里调用捕获和解码(..)?你能分享你的那部分代码吗?当你调用你没有提供的函数时:2个必需的位置参数。您还需要发布Python显示的错误消息,因为在您提供的代码片段中,没有调用
capture\u和。