sách gpt4 ăn đã đi

python - 为什么我的 argparse 抛出 SystemExit 2 错误?

In lại 作者:太空狗 更新时间:2023-10-30 00:18:25 27 4
mua khóa gpt4 giày nike

当我运行我的代码时,它显示在此段中发生了异常:SystemExit2 error at the options = parse.parse_args()。我可以知道这里出了什么问题吗?

nhập khẩu argparse
import queue
import roypy
from sample_camera_info import print_camera_info
from roypy_sample_utils import CameraOpener, add_camera_opener_options
from roypy_platform_utils import PlatformHelper

class MyListener (roypy.IRecordStopListener):
"""A simple listener, in which waitForStop() blocks until onRecordingStopped has been called."""
def __init__ (self):
super (MyListener, self).__init__()
self.queue = queue.Queue()

def onRecordingStopped (self, frameCount):
self.queue.put (frameCount)

def waitForStop (self):
frameCount = self.queue.get()
print ("Stopped after capturing {frameCount} frames".format (frameCount=frameCount))

def main ():
platformhelper = PlatformHelper()
parser = argparse.ArgumentParser (usage = __doc__)
add_camera_opener_options (parser)
parser.add_argument ("--frames", type=int, required=True, help="duration to capture data (number of frames)")
parser.add_argument ("--output", type=str, required=True, help="filename to record to")
parser.add_argument ("--skipFrames", type=int, default=0, help="frameSkip argument for the API method")
parser.add_argument ("--skipMilliseconds", type=int, default=0, help="msSkip argument for the API method")
options = parser.parse_args()

opener = CameraOpener (options)
cam = opener.open_camera ()

print_camera_info (cam)

l = MyListener()
cam.registerRecordListener(l)
cam.startCapture()
cam.startRecording (options.output, options.frames, options.skipFrames, options.skipMilliseconds)

seconds = options.frames * (options.skipFrames + 1) / cam.getFrameRate()
if options.skipMilliseconds:
timeForSkipping = options.frames * options.skipMilliseconds / 1000
seconds = int (max (seconds, timeForSkipping))

print ("Capturing with the camera running at {rate} frames per second".format (rate=cam.getFrameRate()))
print ("This is expected to take around {seconds} seconds".format (seconds=seconds))

l.waitForStop()

cam.stopCapture()

if (__name__ == "__main__"):
chủ yếu()

这是我执行的回溯:

Exception has occurred: SystemExit
2

File "C:\Users\NPStudent\Desktop\Python Code\sample_record_rrf.py", line 44, in main
options = parser.parse_args()

File "C:\Users\NPStudent\Desktop\Python Code\sample_record_rrf.py", line 69, in
chủ yếu()

这是我运行程序时的命令行: nhập mô tả hình ảnh ở đây

câu trả lời hay nhất

您有指定为必需的参数 (required=True),但它们丢失了!您发布的图片清楚地表明了这一点。

在 VSCode 中按 F5 键也会在不带参数的情况下运行它。产生相同的错误,进而导致 VSCode 提示您的脚本崩溃。

您必须使用参数--frames--output 来调用您的程序。首先在命令行上尝试,然后创建一个 launch configuration对于 VSCode。

关于python - 为什么我的 argparse 抛出 SystemExit 2 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54093068/

27 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress