[issue34803] argparse int type does not accept scientific notation

2018-09-27 Thread paul j3
Change by paul j3 : -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker ___ ___

[issue34803] argparse int type does not accept scientific notation

2018-09-26 Thread paul j3
paul j3 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

[issue34803] argparse int type does not accept scientific notation

2018-09-25 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +xtreak ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue34803] argparse int type does not accept scientific notation

2018-09-25 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: You can always do: import argparse foo = int(1e3) # Works: foo = 1000 parser = argparse.ArgumentParser() parser.add_argument( "--foo", type=lambda x: int(float(x))) parser.parse_args( ["--foo=1e3"] ) -- ___

[issue34803] argparse int type does not accept scientific notation

2018-09-25 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: The conversion fails because is trying to convert a string, not a float: >>> int("1e3") *** ValueError: invalid literal for int() with base 10: '1e3' -- nosy: +pablogsal ___ Python tracker

[issue34803] argparse int type does not accept scientific notation

2018-09-25 Thread Jesse Hostetler
Jesse Hostetler added the comment: I suppose desired behavior would be to accept the argument only if it can be converted to int without loss of information. -- ___ Python tracker

[issue34803] argparse int type does not accept scientific notation

2018-09-25 Thread Jesse Hostetler
New submission from Jesse Hostetler : The 'argparse' module gives a parse error for integer arguments written in scientific notation. I would expect this to work, since integers can be constructed from literals in scientific notation. Example (also attached): import argparse foo = int(1e3)