-
Notifications
You must be signed in to change notification settings - Fork 0
argparse
jasper-zanjani edited this page Aug 6, 2020
·
1 revision
Define information that will appear when the user wants help.
The string helptext contains the usage that will appear with -h or --help.
ArgumentParser(description=helptext)Add a positional argument
- positional arguments are valid if only one option is provided
- do not require
-at the beginning of the string -
helpstring is what is printed next to the argument name in thehelpdialog
ArgumentParser.add_argument("x", type=int, help="the base")Add a named parameters
-
-is required at the beginning of the string - values need to be passed after
=or<space> - no longer behaves as a positional argument
ArgumentParser.add_argument('-r','--radius',type=int,required=True,help='radius)Add a group of mutually exclusive arguments (may not be used together)
Usage appears as [-v | -q] indicating one of the options may be used. Many invocation options can be added to the same argument:
qv=ArgumentParser.add_mutually_exclusive_group()
qv.add_argument("-v","--verbose", action="store_true")
qv.add_argument("-q","--quiet","-s","--silent", action="store_true",help='quiet/silent mode')- argparse ?
- array ?
- asyncio ?
- bisect ?
- csv ?
- ctypes ?
- curses ?
- datetime ?
- functools ?
- getpass ?
- glob ?
- heapq ?
- http ?
- json ?
- logging ?
- optparse ?
- os ?
- pathlib ?
- platform ?
- pythonnet ?
- random ?
- socket ?
- subprocess ?
- sqlite3 ?
- sys ?
- termcolor ?
- threading ?
- trace ?
- typing ?
- unittest ?
- urllib ?
- venv ?
- weakref ?
- winrm ?