How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

Michael Torrie torriem at gmail.com
Tue Jan 24 14:05:15 EST 2023


On 1/23/23 18:58, Jach Feng wrote:
> More pathonic, but don't work. The '--' must be at index 1:-)

I'm very confused.  Why are you even using argparse, since if you put --
at index 1 then argparse wont't do any argument parsing at all.  If all
you want is the expression on the command line, just access it directly.
 If it's spread out with spaces, you can do something like this to put
it back together:

expression = " ".join(sys.argv[1:]

Otherwise the standard unix way of doing this is to require the user to
either provide the -- himself, or put the expression in quotes so it's
one unit.





More information about the Python-list mailing list