Python Argparse“需要以下参数"错误 [英] Python Argparse 'following arguments are required' error

查看:38
本文介绍了Python Argparse“需要以下参数"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用github存储库,并且该项目的argparse部分存在一些问题.回购开始像这样:

I'm trying to use a github repo and having some issues with the argparse part of the project. The repo starts like this:

import markdown, sys, csv, getpass, smtplib, argparse
from email.mime.text import MIMEText
from jinja2 import Template


parser = argparse.ArgumentParser()
parser.add_argument('-m', '--markdown', help='Path to Markdown Template', required=True)
parser.add_argument('-c', '--csv', help='Path to CSV file', required=True)
parser.add_argument('-v', '--verbose', help='Write out emails')
args = parser.parse_args() 

我已经输入了markdown和CSV文件的相对路径和绝对路径...,然后得到此错误:

I've entered both the relative and absolute path to both the markdown and CSV files... and I get in return this error:

usage: mass-email.py [-h] -m MARKDOWN -c CSV
mass-email.py: error: the following arguments are required: -m/--markdown, -c/--csv

Process finished with exit code 2

我找不到与此有关的任何具体帮助.任何建议将不胜感激.

I can't find any specific help with this. Any advice would be much appreciated.

推荐答案

使用mass-email.py -m /path/to/my/file -c /path/to/csv

您的参数由其标志定义.如果您希望论据具有定位性,请不要在其前面加上破折号.

Your arguments are defined by their flags. If you want your arguments to be positional, don't include the dashes before them.

parser.add_argument('markdown', help='Path to Markdown Template', required=True)
parser.add_argument('csv', help='Path to CSV file', required=True)

这篇关于Python Argparse“需要以下参数"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆