Why does argparse only work if the python interpre

2019-07-04 17:14发布

I have the python interpreter location in my path environment variable so that I don't need to explicitly call the python interpreter from the command line. However, when I use the argparse module to read command line arguments, it only works if I explicitly call the python interpreter.

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('w')

cmd_args = parser.parse_args()

print(cmd_args.w)

when I don't explicitly call the interpreter, this occurs:

C:\Users\nheme\Desktop> command_line_parse.py test_argument
usage: command_line_parse.py [-h] w
command_line_parse.py: error: the following arguments are required: w

When I explicitly call the interpreter, the code works as expected:

C:\Users\nheme\Desktop> python command_line_parse.py test_argument
test_argument

Why do I need to explicitly call the interpreter?

0条回答
登录 后发表回答