On 23Jan2023 17:58, Jach Feng wrote:
parser.parse_args(['--', 'infix2postfix.py', '-4.3+5'])
usage: [-h] infix
: error: unrecognized arguments: -4.3+5
This error doesn't look like "-4.3+5 looks like an option" but instead
"we don't expect any arguments after "infix".
Not personally a fan
Greg Ewing 在 2023年1月24日 星期二清晨7:33:43 [UTC+8] 的信中寫道:
> >> On 2023-01-22 at 18:19:13 -0800,
> >> Jach Feng wrote:
> >>> 1) Modify the sys.argv by inserting an item '--' before parsing it, ie.
> >>> sys.argv.insert(1, '--')
> >>> args = parser.parse_args()
> If you do that, you'll never be able
On Tue, 24 Jan 2023 at 13:09, Jach Feng wrote:
>
> Chris Angelico 在 2023年1月24日 星期二清晨5:00:27 [UTC+8] 的信中寫道:
> > On Tue, 24 Jan 2023 at 07:47, Cameron Simpson wrote:
> > >
> > > But for Jach Feng: the "--" is really expected as something the user
> > > does when they invoke your programme,
Chris Angelico 在 2023年1月24日 星期二清晨5:00:27 [UTC+8] 的信中寫道:
> On Tue, 24 Jan 2023 at 07:47, Cameron Simpson wrote:
> >
> > But for Jach Feng: the "--" is really expected as something the user
> > does when they invoke your programme, _explicitly_ saying that what
> > follows from here is not an
2qdxy4rz...@potatochowder.com 在 2023年1月24日 星期二凌晨2:47:12 [UTC+8] 的信中寫道:
> On 2023-01-22 at 18:19:13 -0800,
> Jach Feng wrote:
>
> > 1) Modify the sys.argv by inserting an item '--' before parsing it, ie.
> > sys.argv.insert(1, '--')
> > args = parser.parse_args()
> Please don't do that. :-)
>
On 2023-01-22 at 18:19:13 -0800,
Jach Feng wrote:
1) Modify the sys.argv by inserting an item '--' before parsing it, ie.
sys.argv.insert(1, '--')
args = parser.parse_args()
If you do that, you'll never be able to have any actual options, so
using argparse seems like overkill. Just pull the
On Tue, 24 Jan 2023 at 07:47, Cameron Simpson wrote:
>
> But for Jach Feng: the "--" is really expected as something the user
> does when they invoke your programme, _explicitly_ saying that what
> follows from here is not an argument. So the user is expected to type:
>
> your_script -x -y
On 23Jan2023 13:46, 2qdxy4rzwzuui...@potatochowder.com
<2qdxy4rzwzuui...@potatochowder.com> wrote:
On 2023-01-22 at 18:19:13 -0800,
Jach Feng wrote:
1) Modify the sys.argv by inserting an item '--' before parsing it,
ie.
sys.argv.insert(1, '--')
args = parser.parse_args()
Please don't do
On 2023-01-22 at 18:19:13 -0800,
Jach Feng wrote:
> 1) Modify the sys.argv by inserting an item '--' before parsing it, ie.
> sys.argv.insert(1, '--')
> args = parser.parse_args()
Please don't do that. :-)
In my mind, sys.argv belongs to Python, not the application. Instead,
pass a newly
On Tue, 24 Jan 2023 at 04:56, Johannes Bauer wrote:
>
> Hi there,
>
> is there an easy way to evaluate a string stored in a variable as if it
> were an f-string at runtime?
>
> ...
>
> This is supposedly for security reasons. However, when trying to emulate
> this behavior that I wanted (and know
Jach Feng 在 2023年1月22日 星期日上午11:11:22 [UTC+8] 的信中寫道:
> Fail on command line,
>
> e:\Works\Python>py infix2postfix.py "-4^2+5.3*abs(-2-1)/2"
> usage: infix2postfix.py [-h] [infix]
> infix2postfix.py: error: unrecognized arguments: -4^2+5.3*abs(-2-1)/2
>
> Also fail in REPL,
>
>
Hi there,
is there an easy way to evaluate a string stored in a variable as if it
were an f-string at runtime?
I.e., what I want is to be able to do this:
x = { "y": "z" }
print(f"-> {x['y']}")
This prints "-> z", as expected. But consider:
x = { "y": "z" }
s = "-> {x['y']}"
On 2023-01-22, Weatherby,Gerard wrote:
> Argparse is for parsing command line arguments and options.
>
> If you just want to evaluate an Python expression, use eval( )
Only use eval() if the expression is always under your control (and
you don't make mistakes when typing).
Don't use eval() on
13 matches
Mail list logo