Title: Theory / Unimportant / CS / Programming / Python / Lib / ArgParser
Tags: seen_description automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Page: https://docs.python.org/3/howto/argparse.html

Typ: argparse.ArgumentParser(description="foo")
Meaning: A parser for arguments from when the function is called. The help return the description foo
Language: Python

Instruction: argParser.parse_args()
Effect: for the argument --help or -h, write the list of arguments. An error message if an unkwon argument is passed
Language: Python
Returns: An object, allowing to have access to different arguments
Variables: argParser = argparse.ArgumentParser()

Instruction: argParser.add_argument(
  "--foo",
  *args,
  **kwargs,
)
Effect: State that there is one optional arguments, whose name is "foo". It's None if it is not given
Language: Python
Variables: argParser = argparse.ArgumentParser(
)

Instruction: argParser.add_argument(
  *args,
  **kwargs,
  type=plop
)
Effect: State that there is one optional arguments, with type plop.
Language: Python
Context: Arg Parser
Variables: argParser = argparse.ArgumentParser(
)

Instruction: argParser.add_argument(
  "--foo",
  *args,
  **kwargs,
  action="store_true"
)
Effect: State that there may be --foo as arguments, and the returned value will save .foo as true or false according on whether this argument was passed with the program
Language: Python
Context: argparse
Variables: argParser = argparse.ArgumentParser(
)

Instruction: argParser.add_argument(
  "-f",
  "--foo",
  *args,
  **kwargs
)
Effect: State that there is one optional arguments, whose name is "foo", also accessible through -f. It's value is None if it not explicitly given
Language: Python
Variables: argParser = argparse.ArgumentParser(
)

Instruction: argParser.add_argument(
  *args,
  **kwargs,
  choices=[bar_1,
  ...,
  bar_n]
)
Effect: Restricts the possible values to be one of the bar_i
Language: Python
Variables: argParser = argparse.ArgumentParser(
)

Instruction: argParser.add_argument(
  *args,
  **kwargs, action="count"
)
Effect: The optional argument may be given multiple time. When accessed in the code, you get the number of itme it is given
Language: Python
Variables: argParser = argparse.ArgumentParser(
)

Instruction: argParser.add_argument(
  *args,
  **kwargs, default="foo"
)
Effect: If the optional argument is not given, it's default value is foo
Language: Python
Variables: argParser = argparse.ArgumentParser(
)

Instruction: argParser.add_mutually_exclusive_group()
Language: Python
Returns: An object, similar to parser, which can take optional arguments, where no two actions can be used together
Variables: argParser = argparse.ArgumentParser()

Question: It remains
Answer: The entire real documentation https://docs.python.org/3/library/argparse.html#module-argparse
Page: https://docs.python.org/3/howto/argparse.html