Python TypeError: missing 2 required positional arguments // How can I fix it?
Python TypeError: missing 2 required positional arguments // How can I fix it?
我有这个TypeError: capture_and_decode() missing 2 required positional arguments: 'bitrange' and '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_and_decode()
方法旨在采用两个位置参数;即位域和轴。无论您在何处调用此方法,都需要提供以下参数:
cam = CameraClass()
cam.capture_and_decode(500, 4) # or whatever the values should be.
我有这个TypeError: capture_and_decode() missing 2 required positional arguments: 'bitrange' and '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_and_decode()
方法旨在采用两个位置参数;即位域和轴。无论您在何处调用此方法,都需要提供以下参数:
cam = CameraClass()
cam.capture_and_decode(500, 4) # or whatever the values should be.