Reputation:
I keep getting the error: raise ValueError('nargs must be %r to supply const' % OPTIONAL)
when I use the following code in python:
parser = argparse.ArgumentParser()
parser.add_argument('--username', type=str, required=True,
help="Username to login. Required")
parser.add_argument('--password', type=str, required=True,
help="Password to login. Required.")
parser.add_argument('--chromedriver', type=str, const=r'C:\histdata\batfiles\chromedriver.exe')
parser.add_argument('--output', type=str, const='C:\\histdata\\batfiles\\')
It fails on the line for --chromedriver
. When I move the next line before it to test that too. It fails. That is --output
line gives the same error. I realize that people in the past have posted a similar error message, but I still don't see how to fix it.
Upvotes: 2
Views: 1813
Reputation: 499
Maybe you want to use default
instead of const
? The former is used to store the default value of an argument, the latter is for specifying const value, that will be stored, when the argument is provided.
Upvotes: 1