Skip to content
Advertisement

Tag: command-line-arguments

Parsing boolean values with argparse

I would like to use argparse to parse boolean command-line arguments written as “–foo True” or “–foo False”. For example: However, the following test code does not do what I would like: Sadly, parsed_args.my_bool evaluates to True. This is the case even when I change cmd_line to be [“–my_bool”, “”], which is surprising, since bool(“”) evalutates to False. How can

Advertisement