【问题标题】:conflicting options string(s) on second loop第二个循环上的冲突选项字符串
【发布时间】:2017-09-25 21:18:29
【问题描述】:
    #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)

我已经编写了这段代码来记录镜头,然后使用 youtube api 上传到 youtube,但它目前在第二个循环中返回此错误。

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

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

为什么第二个循环会出现这个错误?

【问题讨论】:

  • 你能在你的代码中包含循环吗?
  • @Sweater-Baron 有帮助吗?我是一个非常业余的编码员,所以这可能很混乱......
  • 您刚刚发布的代码似乎失去了缩进。或者你的源文件中的代码也没有缩进?
  • @Sweater-Baron 抱歉,我复制它时出错了。已排序!关于代码的任何其他问题我都非常乐意回答。
  • 第一次通过您将一组arguments 添加到现有的argparser(我相信是由youtube api 创建的)。您不能添加更多同名参数。可以再次调用parse_args,但不能重复使用add_argument('--file'...)

标签: python youtube-api arguments argparse


【解决方案1】:

您多次调用 parser.add_argument("--file") ,而每个参数只能调用一次。只需在进入循环之前将所有 add_argument 调用移到右侧即可。

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

import argparse

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

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

【讨论】:

  • 这很有意义!刚刚从循环中删除了 argparser.add 并将它们放入我的设置中,现在可以正常工作了!感谢您的帮助!
  • 嗨@mhodgy,如果这个或任何答案解决了您的问题,请点击复选标记考虑accepting it。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。
猜你喜欢
  • 2010-12-12
  • 1970-01-01
  • 2021-01-21
  • 2016-09-25
  • 2017-08-10
  • 2013-09-21
  • 1970-01-01
  • 1970-01-01
  • 2016-03-29
相关资源
最近更新 更多