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

Peter J. Holzer hjp-python at hjp.at
Sun Jan 29 08:54:32 EST 2023


On 2023-01-27 21:03:39 -0800, Jach Feng wrote:
> I have to admit that I don't know the background upon which the
> argparse was built. The good side is that I don't carry its historical
> knowledge ( or burden?), that's why I can use it in a new way

I don't see what's new about that.

> which may make someone feel uneasy.

It seems that the person who feels most uneasy about it is yourself
because it doesn't work like you want it to.


> The reason I am still keep on using argparse on this "one positional
> argument only" CLI app is that I can't see what advantage I can get
> when writing code to handling sys.argv directly for the following two
> situations,

It would almost certainly be shorter and easier to understand,
especially since you are *also* handling sys.argv directly in your code
to prevent argparse to work as designed.

But since you are probably the only person who will have to read your
code in the future that's not our problem.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20230129/1b2e83f0/attachment.sig>


More information about the Python-list mailing list