[issue34803] argparse int type does not accept scientific notation

paul j3 report at bugs.python.org
Wed Sep 26 23:35:49 EDT 2018


paul j3 <ajipanca at gmail.com> added the comment:

The `type` parameter is normally a function (or more generally a callable).  When given a string it should convert it as needed, or raise an error.  In your example that function is the stock, 'int()'.

Test `int('123')`, `int('1e3')` etc for yourself to see what it can handle.

If you want to convert '1e3' to an integer, write your own function that handle it.  Don't expect argparse or the stock int() to do it for you.

More commonly people use 'type=bool', expecting it convert 'True' or 'False' strings to boolean values.  But that's not what the bool() function does.

To reiterate, 'type' is a function, not a desired class.

Since this is not a bug, I think this should be closed.

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

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34803>
_______________________________________


More information about the Python-bugs-list mailing list