[issue44748] argparse: a bool indicating if arg was encountered
🖤Black Joker🖤
report at bugs.python.org
Wed Jul 28 03:14:58 EDT 2021
🖤Black Joker🖤 <akki.dw007 at gmail.com> added the comment:
I would like to use argparse to parse boolean command-line arguments written as "--foo True" or "--foo False". For example:
my_program --my_boolean_flag False
However, the following test code does not do what I would like:
import argparse
parser = argparse.ArgumentParser(description="My parser")
parser.add_argument("--my_bool", type=bool)
cmd_line = ["--my_bool", "False"]
parsed_args = parser.parse(cmd_line)
----------
components: +Tests -Library (Lib)
nosy: +joker
versions: +Python 3.9 -Python 3.11
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44748>
_______________________________________
More information about the Python-bugs-list
mailing list