Oct-15-2020, 05:54 AM
(This post was last modified: Oct-15-2020, 05:56 AM by Gribouillis.)
The normal way a Python program receives the command line arguments is in the list
sys.argv
. This list receives any arguments from the command line. No check is done on these arguments or the command line switches. You can call any Python program with the following command linepython myprogram.py foo bar baz --spam=eggs -d oopsWhen you are using the
argparse
module you are narrowing the set of command lines that the program considers as valid. The valid syntax is described by the parser configuration and the call to parser.parse_args()
will examine the contents of the list sys.argv
and transform this list into a 'namespace' instance wich is the args
object caught by the program as the return value. In the meantime, the call rejects any command line syntax that doesn't fulfill the specification of the argparse parser. This namespace object has a semantics defined by the program while sys.argv
's semantics is merely a split of the command line arguments.