PyDocs

Nav

Command-line interface libraries

BooleanOptionalAction

argparse

class · Added in 3.9 (source)
  • BooleanOptionalAction(option_strings, dest, default=None, required=False, help=None, deprecated=False)
A subclass of Action for handling boolean flags with positive and negative options. Adding a single argument such as --foo automatically creates both --foo and --no-foo options, storing True and False respectively:
Changed in 3.15
  • 3.15: Added support for single-dash options. Added support for alternate prefix_chars.
1 Example
>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', action=argparse.BooleanOptionalAction)
>>> parser.parse_args(['--no-foo'])
Namespace(foo=False)
from the Python docs
See Also
No see-alsos for argparse/BooleanOptionalAction
0 Notes
No notes for BooleanOptionalAction