Python Argparse: Issue with optional arguments which are negative numbers

One workaround I’ve found is to quote the value, but adding a space. That is,

./blaa.py --xlim " -2.e-3" 1e4

This way argparse won’t think -2.e-3 is an option name because the first character is not a hyphen-dash, but it will still be converted properly to a float because float(string) ignores spaces on the left.

Leave a Comment