[issue21208] Change default behavior of arguments with type bool when options are specified

paul j3 report at bugs.python.org
Wed May 28 05:55:33 CEST 2014


paul j3 added the comment:

Last year someone asked on Stackoverflow about using 'type=bool'.  My answer is at:

http://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse/19233287#19233287

'type' is supposed to be a function that takes a string, and converts to a desired Python object (e.g. number), and in the process validates it.

The builtin 'bool()' is not a good choice for this. 'bool("")' returns False, all other strings return True, that includes strings like "false", "no", "False".  If you want those strings to be interpreted as boolean False, you need to write your own 'str2bool' function.

But normally boolean values are entered via 'store_true' and 'store_false' actions.

----------
nosy: +paul.j3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21208>
_______________________________________


More information about the Python-bugs-list mailing list