Reputation: 161
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()
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.
Upvotes: 1
Views: 14571
Reputation: 66
Seems like you may be running it from the IDE without giving any command line arguments. I see you are using pycharm, so check this post about passing in command line arguments to pycharm runs:
Pycharm and sys.argv arguments
Upvotes: 1
Reputation: 2497
Call your script with 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)
Upvotes: 2