How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?
Michael Torrie
torriem at gmail.com
Sun Jan 22 18:38:59 EST 2023
On 1/22/23 11:44, Stefan Ram wrote:
> Jach Feng <jfong at ms4.hinet.net> writes:
>> e:\Works\Python>py infix2postfix.py "-4^2+5.3*abs(-2-1)/2"
>
> Well, it's a nice exercise! But I only made it work for the
> specific example given. I have not tested whether it always
> works.
Haha. Yes a nice exercise, but has nothing to do with the original
question which is how to convince argparse to accept a string like that
without thinking it's a switch. Many unix utilities treat "--" as a
special argument that turns off argument parsing for the rest of the
command line. Maybe argparse follows this convention too; I don't know.
But if it did you'd do:
infix2postfix.py -- "-4^2+5.3*abs(-2-1)/2"
More information about the Python-list
mailing list