Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
parser.parse_args() meaning
#2
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 line
python myprogram.py foo bar baz --spam=eggs -d oops
When 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.
vinci likes this post
Reply


Messages In This Thread
parser.parse_args() meaning - by vinci - Oct-14-2020, 09:09 PM
RE: parser.parse_args() meaning - by Gribouillis - Oct-15-2020, 05:54 AM
RE: parser.parse_args() meaning - by vinci - Oct-26-2020, 04:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to understand the meaning of the line of code. jahuja73 0 328 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Csv writer meaning of quoting mg24 2 1,187 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
  meaning of -> syntax in function definition DrakeSoft 5 2,017 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Operator meaning explanation Sherine 3 2,082 Jul-31-2021, 11:05 AM
Last Post: Sherine
  What is the meaning of k in this function? giladal 3 2,767 Aug-15-2020, 12:32 PM
Last Post: buran
  Here what is the meaning of span=(1,2) ,match='1'? srisrinu 1 2,138 Apr-27-2020, 10:22 AM
Last Post: anbu23
  What is the meaning of mutable data type? qliu 3 2,994 Apr-17-2020, 07:20 PM
Last Post: deanhystad
  Upper-Bound Exclusive Meaning Johnny1998 1 3,390 Aug-02-2019, 08:32 PM
Last Post: ichabod801
  Finding phrases of one semantic meaning VladislavMz 2 31,891 Dec-20-2018, 03:29 AM
Last Post: VladislavMz
  Meaning of some term? hsunteik 2 4,314 Dec-21-2016, 05:47 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020