argparse store false if unspecified


parser.add_argument("-auto", action="store_true")

How can I store false if -auto is unspecified? I can faintly remember that this way, it stores None if unspecified

Answer rating: 217

The store_true option automatically creates a default value of False.

Likewise, store_false will default to True when the command-line argument is not present.

The source for this behavior is succinct and clear:

The argparse docs aren"t clear on the subject, so I"ll update them now:

Get Solution for free from DataCamp guru