Fix Python – Creating hidden arguments with Python argparse

Question

Asked By – Peter Smit

Is it possible to add an Argument to an python argparse.ArgumentParser without it showing up in the usage or help (script.py --help)?

Now we will see solution for issue: Creating hidden arguments with Python argparse


Answer

Yes, you can set the help option to add_argument to argparse.SUPPRESS. Here’s an example from the argparse documentation:

>>> parser = argparse.ArgumentParser(prog='frobble')
>>> parser.add_argument('--foo', help=argparse.SUPPRESS)
>>> parser.print_help()
usage: frobble [-h]

optional arguments:
  -h, --help  show this help message and exit

This question is answered By – srgerg

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0