Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 第二个循环上的冲突选项字符串_Python_Youtube Api_Arguments_Argparse - Fatal编程技术网

Python 第二个循环上的冲突选项字符串

Python 第二个循环上的冲突选项字符串,python,youtube-api,arguments,argparse,Python,Youtube Api,Arguments,Argparse,我编写了一段代码,它记录了视频片段,然后使用youtube api上传到youtube,但目前它在第二个循环中返回了这个错误 ArgumentError:参数--file:冲突的选项字符串--file filename='mergedVideo'+str(N)+'.mkv'并在每次运行程序时增加 为什么在第二个循环中会发生此错误?您多次调用parser.add_参数(“--file”),而每个参数只能调用一次。只需在进入循环之前将所有add_参数调用移到右边 运行此代码可能有助于了解出了什么问题

我编写了一段代码,它记录了视频片段,然后使用youtube api上传到youtube,但目前它在第二个循环中返回了这个错误

ArgumentError:参数--file:冲突的选项字符串--file

filename='mergedVideo'+str(N)+'.mkv'
并在每次运行程序时增加


为什么在第二个循环中会发生此错误?

您多次调用parser.add_参数(“--file”),而每个参数只能调用一次。只需在进入循环之前将所有add_参数调用移到右边

运行此代码可能有助于了解出了什么问题:

    #main loop 
while 1==1:
    #If they click Yes on the dialog box begin recording, otherwise ask again
    easygui.msgbox('This is what the last person suggested! Press ok to record.: ' + output_string, 'Title', ok_button= "OK")
    N+=1
    counterFile = open('counterFile','w')
    counterFile.write(str(N));
    counterFile.close()
    camera.start_recording('video' + str(N) + '.h264')
    audioRecord() 
    camera.stop_recording()
    output_string_old = output_string;
    output_string = TextEnter()
    filename = ConvertMerge()
    argparser.add_argument("--file")
    argparser.add_argument("--title")
    argparser.add_argument("--description")
    argparser.add_argument("--category")
    argparser.add_argument("--keywords")
    argparser.add_argument("--privacyStatus")
    args = argparser.parse_args(["--file", filename, "--title", str(N),"--description", output_string_old, "--category", "22", "--keywords", " ", "--privacyStatus", "public"])
    initialize_upload(get_authenticated_service(args), args)

您会注意到在循环的第二次出现错误,因为您已经添加了一个名为“-file”的参数。

您可以在代码中包含循环吗?@sweeter Baron这样做有帮助吗?我是一个非常业余的程序员,所以这可能是非常混乱的…你刚刚发布的代码似乎已经失去了缩进。或者代码在源文件中也没有缩进?@sweeter Baron很抱歉,我在复制时出错了。分类!关于代码的任何其他问题,我都非常乐意回答。第一次通过您向现有的
argparser
(我相信是由
youtube
api创建的)添加了一组
参数。不能添加更多同名参数。您可以再次调用
parse_args
,但不能重用
add_参数('--file'…)
。这很有意义!刚从循环中删除了argparser.add,并将它们放在我的设置中,现在可以正常工作了!谢谢你的帮助!如果这个或任何答案解决了你的问题,请点击检查标记来考虑。这向更广泛的社区表明,你已经找到了一个解决方案,并给回答者和你自己带来了一些声誉。没有义务这样做。
import argparse

parser = argparse.ArgumentParser(description='test')
for i in range(2):
    print i
    parser.add_argument("--file")
    parser.add_argument("stuff")