Questions tagged «multiple-arguments»

3
在Python的argparse中多次使用相同的选项
我正在尝试编写一个脚本,该脚本接受多个输入源并对每个输入源都执行某项操作。像这样 ./my_script.py \ -i input1_url input1_name input1_other_var \ -i input2_url input2_name input2_other_var \ -i input3_url input3_name # notice inputX_other_var is optional 但是我不太清楚如何使用argparse。似乎已设置好,因此每个选项标志只能使用一次。我知道如何将多个参数与单个选项(nargs='*'或nargs='+')关联,但这仍然不允许我-i多次使用该标志。我该如何完成这项工作? 为了清楚起见,我最后想要的是一个字符串列表列表。所以 [["input1_url", "input1_name", "input1_other"], ["input2_url", "input2_name", "input2_other"], ["input3_url", "input3_name"]]
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.