Re: argparse argument post-processing

2023-11-27 Thread Dom Grigonis via Python-list
Yeah, I have been hearing that people are having troubles converting, but I have only used argparse - got lucky there I guess. I am thinking just making the function which spits the class out. Maybe not very optimised solution, but simple. Argument parsing in my case is very far from being a

Re: argparse argument post-processing

2023-11-27 Thread Mats Wichmann via Python-list
27;ve worked more with optparse (the project I work on that uses it has reasons why it's not feasible to convert to argparse); in optparse you use a callback function, rather than an action class, and the change to a callable class is somewhat significant :-; so I'm not really an expert.

Re: argparse argument post-processing

2023-11-27 Thread Dom Grigonis via Python-list
h3') and convert it to the desired output - list: >> import argparse >> parser = argparse.ArgumentParser() >> parser.add_argument('paths', type=lambda x: list(filter(str.strip, >> x.split(',' >> So far so good. But this is just an examp

Re: argparse argument post-processing

2023-11-27 Thread Mats Wichmann via Python-list
On 11/27/23 04:29, Dom Grigonis via Python-list wrote: Hi all, I have a situation, maybe someone can give some insight. Say I want to have input which is comma separated array (e.g. paths='path1,path2,path3') and convert it to the desired output - list: import argpa

Re: argparse argument post-processing

2023-11-27 Thread Chris Angelico via Python-list
utput - list: This is a single argument. > Now the second case. I want input to be space separated array - bash array. > And I want space-separated string returned. My current approach is: > import argparse > parser = argparse.ArgumentParser() > parser.add_argument('path

argparse argument post-processing

2023-11-27 Thread Dom Grigonis via Python-list
Hi all, I have a situation, maybe someone can give some insight. Say I want to have input which is comma separated array (e.g. paths='path1,path2,path3') and convert it to the desired output - list: import argparse parser = argparse.ArgumentParser() parser.add_argument('paths&

Re: Add angle brackets for required args in argparse

2023-02-22 Thread scruel tao
e name or >>> signature of that method changes (even if it does work with all current >>> versions, it might break in future). Your are right to be concerned, that’s why I still think, might the `argparse` can provide a more stable way which can set such format strategy global

Re: Add angle brackets for required args in argparse

2023-02-20 Thread Mark Bourne
However, I hope the message can be as the following: ``` usage: test.py [-h] test.py: error: the following arguments are required: path ``` The `metavar` argument to `add_argument` can be used to control how an argument is represented in the usage text: ``` import argparse parser = arg

Add angle brackets for required args in argparse

2023-02-15 Thread scruel tao
If we have the following code: ``` parser = argparse.ArgumentParser(description="test") parser.add_argument('path') ``` Run it without args, will get error message: ``` usage: test.py [-h] path test.py: error: the following arguments are required: path ``` However, I hope the message can be as th

Re: Custom help format for a choice argparse argument

2023-01-30 Thread Peter Otten
") This works, but is there a more elegant way to achieve it? It may be sufficient to specify a metavar: >>> import argparse >>> p = argparse.ArgumentParser() >>> p.add_argument("--foo", choices="alpha beta gamma".split(), metavar=""

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

2023-01-29 Thread Cameron Simpson
On 29Jan2023 08:10, avi.e.gr...@gmail.com wrote: You are technically correct but perhaps off the mark. Yes, a python program only sees what is handed to it by some shell if invoked a certain way. The issue here is what you tell people using your program about what they need to type to get it

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

2023-01-29 Thread Cameron Simpson
On 29Jan2023 07:12, 2qdxy4rzwzuui...@potatochowder.com <2qdxy4rzwzuui...@potatochowder.com> wrote: On 2023-01-29 at 16:51:20 +1100, Cameron Simpson wrote: They're unrelated. As others have mentioned, "--" is _extremely_ common; almost _all_ UNIX command like programmes which handle -* style o

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

2023-01-29 Thread Ethan Furman
This thread has run its course and seems to now be generating more heat than light. It is now closed (at least on the Python List side). Thank you everyone for your participation and understanding. -- ~Ethan~ Moderator -- https://mail.python.org/mailman/listinfo/python-list

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

2023-01-29 Thread Mark Bourne
quot;-" for options anyway). But more to the point, it is a feature that is implemented under your application's control (if you don't want this feature, don't use argparse). Use of "--" is applicable regardless of which shell your user calls it from, and other

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

2023-01-29 Thread Mark Bourne
\Works\Python>py Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import argparse parser = argparse.ArgumentParser(description='Con

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

2023-01-29 Thread Jach Feng
Also fail in REPL, > > e:\Works\Python>py > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> impor

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

2023-01-29 Thread Peter J. Holzer
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&#

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

2023-01-29 Thread Peter J. Holzer
On 2023-01-29 07:59:21 -0500, avi.e.gr...@gmail.com wrote: > Although today you could say POSIX is the reason for many things including > the use of "--" I hesitate to mention I and many others used that convention > long before as a standard part of many UNIX utilities. I somewhat doubt that you

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

2023-01-29 Thread avi.e.gross
"--" ... -Original Message- From: Python-list On Behalf Of Cameron Simpson Sent: Sunday, January 29, 2023 12:51 AM To: python-list@python.org Subject: Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument? On 28Jan2023 18:55, Jach Feng wrote: >Mark Bour

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

2023-01-29 Thread avi.e.gross
tandardize, ... -Original Message- From: Python-list On Behalf Of 2qdxy4rzwzuui...@potatochowder.com Sent: Sunday, January 29, 2023 7:12 AM To: python-list@python.org Subject: Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument? On 2023-01-29 at 16:51:20 +1100, Ca

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

2023-01-29 Thread 2QdxY4RzWzUUiLuE
On 2023-01-29 at 16:51:20 +1100, Cameron Simpson wrote: > They're unrelated. As others have mentioned, "--" is _extremely_ common; > almost _all_ UNIX command like programmes which handle -* style options > honour the "--" convention. _argparse_ itself honours that convention, as > does getopt et

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

2023-01-28 Thread Cameron Simpson
On 28Jan2023 18:55, Jach Feng wrote: Mark Bourne 在 2023年1月28日 星期六晚上10:00:01 [UTC+8] 的信中寫道: I notice you explain the need to enclose the equation in quotes if it contains spaces. That's not even a feature of your application, but of the shell used to call it. So why so much objection to explaini

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

2023-01-28 Thread Chris Angelico
o the subprocess spawner). Maybe you come from Windows, where there are fewer conventions and less shell parsing, but argparse follows Unix conventions, so if you don't want Unix conventions, don't use argparse. Just read sys.argv directly. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

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

2023-01-28 Thread avi.e.gross
to do what you want. -Original Message- From: Python-list On Behalf Of Jach Feng Sent: Saturday, January 28, 2023 12:04 AM To: python-list@python.org Subject: Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument? Jach Feng 在 2023年1月22日 星期日上午11:11:22 [UTC+8]

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

2023-01-28 Thread Jach Feng
C v.1928 32 > >> bit (Intel)] on win32 > >> Type "help", "copyright", "credits" or "license" for more information. > >>>>> import argparse > >>>>> parser = argparse.ArgumentParser(description='Convert

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

2023-01-28 Thread Jach Feng
Also fail in REPL, > > e:\Works\Python>py > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> impor

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

2023-01-28 Thread Mark Bourne
\Works\Python>py Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import argparse parser = argparse.ArgumentParser(description='Con

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

2023-01-27 Thread Michael Torrie
On 1/25/23 19:50, Jach Feng wrote: > To me, argparse has been just a tool which I can use in a CLI app. argparse is just a tool for dealing with command-line *flags*, which are common in command-line tools. argparse interprets the command line as a bunch of flags because that's w

Re: Custom help format for a choice argparse argument

2023-01-27 Thread Thomas Passin
-h still shows all the contents of pytz.all_timezones. Adding a few arguments makes it work (with the help of the argparse doc page and Stack Overflow: https://stackoverflow.com/questions/14950964/overriding-default-argparse-h-behaviour): import argparse import pytz HELP ="""

Re: Custom help format for a choice argparse argument

2023-01-27 Thread Ivan "Rambius" Ivanov
Hello Cameron, On Fri, Jan 27, 2023 at 4:45 PM Cameron Simpson wrote: > > On 27Jan2023 15:31, Ivan "Rambius" Ivanov > wrote: > >I am developing a script that accepts a time zone as an option. The > >time zone can be any from pytz.all_timezones. I have > > > >def main(): > >parser = argparse

Re: Custom help format for a choice argparse argument

2023-01-27 Thread Cameron Simpson
On 27Jan2023 15:31, Ivan "Rambius" Ivanov wrote: I am developing a script that accepts a time zone as an option. The time zone can be any from pytz.all_timezones. I have def main(): parser = argparse.ArgumentParser() parser.add_argument("-z", "--zone", choices=pytz.all_timezones) [...]

Re: Custom help format for a choice argparse argument

2023-01-27 Thread Ivan "Rambius" Ivanov
y, January 27, 2023 at 3:33 PM > To: Python > Subject: Custom help format for a choice argparse argument > > *** Attention: This is an external email. Use caution responding, opening > attachments or clicking on links. *** > > Hello, > > I am developing a script that accepts

Re: Custom help format for a choice argparse argument

2023-01-27 Thread Weatherby,Gerard
van "Rambius" Ivanov Date: Friday, January 27, 2023 at 3:33 PM To: Python Subject: Custom help format for a choice argparse argument *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hello, I am developing a script that ac

Custom help format for a choice argparse argument

2023-01-27 Thread Ivan "Rambius" Ivanov
Hello, I am developing a script that accepts a time zone as an option. The time zone can be any from pytz.all_timezones. I have def main(): parser = argparse.ArgumentParser() parser.add_argument("-z", "--zone", choices=pytz.all_timezones) args = parser.parse_args() print(args)

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

2023-01-26 Thread Mats Wichmann
On 1/24/23 23:28, Jach Feng wrote: Chris Angelico 在 2023年1月25日 星期三下午1:16:25 [UTC+8] 的信中寫道: On Wed, 25 Jan 2023 at 14:42, Jach Feng wrote: I was happy working with argparse during implement my script. To save the typing, I used a default equation for testing. sample = "-4^2+5.3*abs(-2

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

2023-01-25 Thread Chris Angelico
On Thu, 26 Jan 2023 at 14:13, Jach Feng wrote: > Now I understand some oppose this idea and saying that you shouldn't use a > kitchen knife to cut a cake:-) You shouldn't use a chainsaw to cut a cake, and then ask us why cake-cutting is so noisy. ChrisA -- https://mail.python.org/mailman/listi

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

2023-01-25 Thread Jach Feng
Also fail in REPL, > > e:\Works\Python>py > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> impor

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

2023-01-25 Thread David
On Thu, 26 Jan 2023 at 04:24, Jach Feng wrote: > Chris Angelico 在 2023年1月25日 星期三下午1:16:25 [UTC+8] 的信中寫道: > > On Wed, 25 Jan 2023 at 14:42, Jach Feng wrote: > > You're still not really using argparse as an argument parser. Why not > > just do your own -h checking? Stop

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

2023-01-25 Thread Weatherby,Gerard
ult, controlling the number of arguments and the like. From: Python-list on behalf of Jach Feng Date: Wednesday, January 25, 2023 at 12:25 PM To: python-list@python.org Subject: Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument? *** Attention: This is an external

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

2023-01-25 Thread Chris Angelico
On Thu, 26 Jan 2023 at 04:25, Jach Feng wrote: > > Chris Angelico 在 2023年1月25日 星期三下午1:16:25 [UTC+8] 的信中寫道: > > On Wed, 25 Jan 2023 at 14:42, Jach Feng wrote: > > > I was happy working with argparse during implement my script. To save the > > > typing, I used

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

2023-01-25 Thread Jach Feng
Chris Angelico 在 2023年1月25日 星期三下午1:16:25 [UTC+8] 的信中寫道: > On Wed, 25 Jan 2023 at 14:42, Jach Feng wrote: > > I was happy working with argparse during implement my script. To save the > > typing, I used a default equation for testing. > > > > sample = "-4^2+5

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

2023-01-24 Thread Cameron Simpson
On 25Jan2023 16:15, Chris Angelico wrote: On Wed, 25 Jan 2023 at 14:42, Jach Feng wrote: I was happy working with argparse during implement my script. To save the typing, I used a default equation for testing. Sure, but what benefit was it bringing you? Just the usage (help) message? Did

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

2023-01-24 Thread Chris Angelico
On Wed, 25 Jan 2023 at 14:42, Jach Feng wrote: > I was happy working with argparse during implement my script. To save the > typing, I used a default equation for testing. > > sample = "-4^2+5.3*abs(-2-1)/2, abs(Abc)*(B+C)/D, (-3) * > sqrt(1-(x1/7)*(y1/7)) * sqrt(abs((x0-4.5

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

2023-01-24 Thread Jach Feng
Also fail in REPL, > > e:\Works\Python>py > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> impor

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

2023-01-24 Thread Jach Feng
g the issue. > -Original Message- > From: Python-list On > Behalf Of Jach Feng > Sent: Tuesday, January 24, 2023 2:21 AM > To: pytho...@python.org > Subject: Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string > argument? > cameron...@gmai

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

2023-01-24 Thread Jach Feng
Michael Torrie 在 2023年1月25日 星期三凌晨3:05:44 [UTC+8] 的信中寫道: > 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 argpars

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

2023-01-24 Thread Dennis Lee Bieber
On Tue, 24 Jan 2023 15:13:33 + (UTC), Mike Baskin declaimed the following: >Can you stop please > Stop what? You appear to be subscribed to the Python mailing list -- as such you WILL receive all traffic that appears on that list. There is nothing we can do. It is not a pers

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

2023-01-24 Thread avi.e.gross
pression are evaluated or changed before python is even invoked. Then again, I may be misunderstanding the issue. -Original Message- From: Python-list On Behalf Of Jach Feng Sent: Tuesday, January 24, 2023 2:21 AM To: python-list@python.org Subject: Re: How to make argparse accep

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

2023-01-24 Thread Mike Baskin via Python-list
an argument. So the user is expected to type: >>>> >>>> your_script -x -y -- "-4^2+5.3*abs(-2-1)/2" >>>> >>>> where there are -x and -y options, then end of options, then an >>>> argument, which would look like an option if the

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

2023-01-24 Thread Mike Baskin via Python-list
nized 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 of argparse myself, but then I have my own elaborate command line framework which generally uses

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

2023-01-24 Thread Jach Feng
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 of argparse myself, but then I have my own > elaborate command line framework which generally uses getopt

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

2023-01-24 Thread Michael Torrie
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 expressi

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

2023-01-24 Thread Weatherby,Gerard
I understand we all want to be helpful and friendly, but it seems to me that helping someone use the wrong tool for the job isn’t really helpful in the long run. argparse is for parsing command line arguments. It’s the wrong tool for this job. As Chris Angelico already said: This entire

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

2023-01-24 Thread Thomas Passin
o type: >>>> >>>> your_script -x -y -- "-4^2+5.3*abs(-2-1)/2" >>>> >>>> where there are -x and -y options, then end of options, then an >>>> argument, which would look like an option if there was

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

2023-01-24 Thread Thomas Passin
if there wasn't the "--" argument. And if you DON'T expect the user to enter the "--", then why use argparse? You can just check argv directly to get your arguments. This entire thread is a massive "how can I use X to do Y?" problem. ChrisA The '--' req

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

2023-01-23 Thread Cameron Simpson
ect any arguments after "infix". Not personally a fan of argparse myself, but then I have my own elaborate command line framework which generally uses getopt for the option stuff. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

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

2023-01-23 Thread Jach Feng
>> 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 argument out of > argv directly. > > -- > Greg Any easy way to "pull the argument out of argv directly" before parse_args()?:-) -- https://mail.python.org/mailman/listinfo/python-list

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

2023-01-23 Thread Chris Angelico
ptions, then end of options, then an > > > argument, which would look like an option if there wasn't the "--" > > > argument. > > And if you DON'T expect the user to enter the "--", then why use > > argparse? You can just check argv di

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

2023-01-23 Thread Jach Feng
re wasn't the "--" > > argument. > And if you DON'T expect the user to enter the "--", then why use > argparse? You can just check argv directly to get your arguments. > > This entire thread is a massive "how can I use X to do Y?" prob

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

2023-01-23 Thread Jach Feng
tual arguments) will work until your > program actually has options. > > 2) By adding an extra space character before the leading '-' sign, ie. > > e:\Works\Python>py infix2postfix.py " -4^2+5.3*abs(-2-1)/2" > > -4 2 ^ 5.3 -2 1 - abs * 2 / + > >

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

2023-01-23 Thread Greg Ewing
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 lik

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

2023-01-23 Thread Chris Angelico
> your_script -x -y -- "-4^2+5.3*abs(-2-1)/2" > > where there are -x and -y options, then end of options, then an > argument, which would look like an option if there wasn't the "--" > argument. And if you DON'T expect the user to enter the &qu

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

2023-01-23 Thread Cameron Simpson
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 th

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

2023-01-23 Thread 2QdxY4RzWzUUiLuE
ign, ie. > e:\Works\Python>py infix2postfix.py " -4^2+5.3*abs(-2-1)/2" > -4 2 ^ 5.3 -2 1 - abs * 2 / + > > But no idea how it works? and if it can survive in a newer argparse > version?:-) It works because argparse checks the first character of each argument, a

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

2023-01-23 Thread Jach Feng
Also fail in REPL, > > e:\Works\Python>py > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> impor

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

2023-01-23 Thread Grant Edwards
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&#

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

2023-01-22 Thread Michael Torrie
s. 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 co

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

2023-01-22 Thread Cameron Simpson
the script parsing the options. I'm pretty sure argparse gives that support for free, as does getopt and probably any others implementing "normal UNIXish options". SO try adding a "--" argument and see how it behaves. Also fail in REPL, e:\Works\Python>py Pytho

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

2023-01-22 Thread Weatherby,Gerard
Argparse is for parsing command line arguments and options. If you just want to evaluate an Python expression, use eval( ) Your string isn’t valid Python due to order of operations, but -(4^2)+5.3*abs(-2-1)/2 is. From: Python-list on behalf of Jach Feng Date: Sunday, January 22, 2023 at 11

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

2023-01-22 Thread Thomas Passin
On 1/22/2023 10:45 AM, Peter J. Holzer wrote: Notice that this file is in its first release, version 0.0.1 - the metadata that says it's 'Development Status :: 5 - Production/Stable' seems to be bogus. So it may very well be buggy. It is at least too incomplete to be useful. It handles only sin

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

2023-01-22 Thread Mark Bourne
Feb 19 2021, 13:08:11) [MSC v.1928 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import argparse parser = argparse.ArgumentParser(description='Convert infix notation to postfix') parser.par

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

2023-01-22 Thread Jach Feng
ix.py: error: unrecognized arguments: -4^2+5.3*abs(-2-1)/2 > > > > Also fail in REPL, > > > > e:\Works\Python>py > > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 > > bit (Intel)] on win32 > > Type "help&qu

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

2023-01-22 Thread Peter J. Holzer
abs(-2-1)/2 [...] > > > > > import argparse > > > > > parser = argparse.ArgumentParser(description='Convert infix notation > > > > > to postfix') > > > > > parser.parse_args("-4^2+5.3*abs(-2-1)/2") > > usage: [-h] &g

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

2023-01-21 Thread Thomas Passin
8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import argparse parser = argparse.ArgumentParser(description='Convert infix notation to po

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

2023-01-21 Thread Jach Feng
:11) [MSC v.1928 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import argparse >>> parser = argparse.ArgumentParser(description='Convert infix notation to >>> postfix

Re: argparse — adding a --version flag in the face of positional args

2022-11-28 Thread Chris Angelico
t; detection of the presence of the positional arg to the application. > >> Shouldn't I be able to tell argparse I'm going to process --verbose, then > >> exit? > > > > ummm, hate to say this, but have you checked the documentation? this

Re: argparse — adding a --version flag in the face of positional args

2022-11-28 Thread Dennis Lee Bieber
On Sun, 27 Nov 2022 22:23:16 -0600, Karen Park declaimed the following: >I figured it out…there was a logistics file given with the assignment! I >thought it was supposed to be a download included with the python >download…oops! > I think you made this response in the wrong thread...

Re: argparse — adding a --version flag in the face of positional args

2022-11-28 Thread Loris Bennett
figure that out. I always get a >> complaint about the required positional argument. >> I think I could use something like nargs='*', but that would push >> off >> detection of the presence of the positional arg to the application. >> Shouldn't I be able t

Re: argparse — adding a --version flag in the face of positional args

2022-11-28 Thread Skip Montanaro
ple action works well enough for my needs, but it would be nice if more than one such option could be given. For example: import argparse parser = argparse.ArgumentParser() parser.add_argument("url") parser.add_argument("--version", version="777", action="version

Re: argparse — adding a --version flag in the face of positional args

2022-11-28 Thread Weatherby,Gerard
More better: import argparse parser = argparse.ArgumentParser() parser.add_argument("positional",type=int) parser.add_argument('--version',action="version",version="2.0") args = parser.parse_args() # double argument print(args.positional * 2) From: Pyt

Re: argparse — adding a --version flag in the face of positional args

2022-11-27 Thread Karen Park
s, but have you checked the documentation? this >> case is supported using an action named 'version' without doing very much. >> > > Thanks, Mats. > > I actually searched all over the argparse docs. (There's a lot to digest. > Honestly, if I wasn't

Re: argparse — adding a --version flag in the face of positional args

2022-11-27 Thread Skip Montanaro
> > ummm, hate to say this, but have you checked the documentation? this > case is supported using an action named 'version' without doing very much. > Thanks, Mats. I actually searched all over the argparse docs. (There's a lot to digest. Honestly, if I wasn'

Re: argparse — adding a --version flag in the face of positional args

2022-11-27 Thread Weatherby,Gerard
Use two parsers: import argparse import sys vparser = argparse.ArgumentParser(add_help=False) vparser.add_argument('--version',action="store_true",help="show version") # look for version, ignore remaining arguments vargs, _ = vparser.parse_known_args() if vargs.v

Re: argparse — adding a --version flag in the face of positional args

2022-11-27 Thread Mats Wichmann
e required positional argument. I think I could use something like nargs='*', but that would push off detection of the presence of the positional arg to the application. Shouldn't I be able to tell argparse I'm going to process --verbose, then exit? ummm, hate to say this, but have

Re: argparse — adding a --version flag in the face of positional args

2022-11-27 Thread Skip Montanaro
7;t occur to me. I looked briefly at the code for argparse to see how it handled --help. The added argument seemed normal, so gave up, figuring there was some special handling of that option. Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: argparse — adding a --version flag in the face of positional args

2022-11-27 Thread Matt Wheeler
I wondered whether subparsers might work, but they don't quite fit here. This seems to fit the bill fairly well, though I agree it would be nice if there were a neater option: import argparse import sys VERSION = 0.1 def main(args): parser.parse_args(args) class VersionA

argparse — adding a --version flag in the face of positional args

2022-11-27 Thread Skip Montanaro
could use something like nargs='*', but that would push off detection of the presence of the positional arg to the application. Shouldn't I be able to tell argparse I'm going to process --verbose, then exit? Thx, Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: argparse modify

2022-06-24 Thread Dennis Lee Bieber
On Thu, 23 Jun 2022 17:01:42 -0600, Mats Wichmann declaimed the following: >Assuming: that the "value" in your init method signature was supposed to >be 'name' since that's what you use later - and would explain your >exception! > Since it is a "named int", I'd expect value to the intege

Re: argparse modify

2022-06-24 Thread נתי שטרן
t; > declaimed the following: > > > > >??? wrote at 2022-6-23 15:31 +0300: > > >>how to solve this (argparse) > > > > >>MAXREPEAT = _NamedIntConstant(32,name=str(32)) > > >>TypeError: 'name' is an invalid keyword argument for int() >

Re: argparse modify

2022-06-24 Thread Roel Schroeven
Op 24/06/2022 om 0:32 schreef Dennis Lee Bieber: On Thu, 23 Jun 2022 18:57:31 +0200, "Dieter Maurer" declaimed the following: >??? wrote at 2022-6-23 15:31 +0300: >>how to solve this (argparse) >>MAXREPEAT = _NamedIntConstant(32,name=str(32)) >>TypeErro

argparse modify

2022-06-24 Thread נתי שטרן
Can you help me for solve it בתאריך יום שישי, 24 ביוני 2022, מאת Dennis Lee Bieber : > On Thu, 23 Jun 2022 18:57:31 +0200, "Dieter Maurer" > declaimed the following: > > >??? wrote at 2022-6-23 15:31 +0300: > >>how to solve this (argparse) > > >

Fwd: argparse modify

2022-06-23 Thread נתי שטרן
הודעה שהועברה -- מאת: *Dieter Maurer* תאריך: יום שישי, 24 ביוני 2022 נושא: argparse modify אל: נתישטרן עותק: "python-list-requ...@python.org" , " python-list@python.org" נתי שטרן wrote at 2022-6-24 08:28 +0300: >I copied code from argparse

Re: argparse modify

2022-06-23 Thread Dieter Maurer
נתי שטרן wrote at 2022-6-24 08:28 +0300: >I copied code from argparse library and modified it > >בתאריך יום חמישי, 23 ביוני 2022, מאת Dieter Maurer : > >> נתי שטרן wrote at 2022-6-23 15:31 +0300: >> >how to solve this (argparse) >> > >> > >&g

Re: argparse modify

2022-06-23 Thread נתי שטרן
I copied code from argparse library and modified it בתאריך יום חמישי, 23 ביוני 2022, מאת Dieter Maurer : > נתי שטרן wrote at 2022-6-23 15:31 +0300: > >how to solve this (argparse) > > > > > >traceback: > >Traceback (most recent call last): > > File "

Re: argparse modify

2022-06-23 Thread Chris Angelico
On Fri, 24 Jun 2022 at 09:03, Mats Wichmann wrote: > Also note that while it's claimed to be fine These Days, inheriting from > a base type like this is sometimes tricky, sometimes broken... be > somewhat aware. Depends on your definition of "broken". If you want to make a custom integer type, yo

Re: argparse modify

2022-06-23 Thread Mats Wichmann
On 6/23/22 16:32, Dennis Lee Bieber wrote: > On Thu, 23 Jun 2022 18:57:31 +0200, "Dieter Maurer" > declaimed the following: > >> ??? wrote at 2022-6-23 15:31 +0300: >>> how to solve this (argparse) > >>>MAXREPEAT = _NamedIntConstant(32,nam

Re: argparse modify

2022-06-23 Thread Dennis Lee Bieber
On Thu, 23 Jun 2022 18:57:31 +0200, "Dieter Maurer" declaimed the following: >??? wrote at 2022-6-23 15:31 +0300: >>how to solve this (argparse) >>MAXREPEAT = _NamedIntConstant(32,name=str(32)) >>TypeError: 'name' is an invalid keyword argumen

Re: argparse modify

2022-06-23 Thread Dieter Maurer
נתי שטרן wrote at 2022-6-23 15:31 +0300: >how to solve this (argparse) > > >traceback: >Traceback (most recent call last): > File "u:\oracle\RTR.py", line 10, in >class sre_constants(): > File "u:\oracle\RTR.py", line 77, in sre_constants >

argparse modify

2022-06-23 Thread נתי שטרן
how to solve this (argparse) traceback: Traceback (most recent call last): File "u:\oracle\RTR.py", line 10, in class sre_constants(): File "u:\oracle\RTR.py", line 77, in sre_constants MAXREPEAT = _NamedIntConstant(32,name=str(32)) TypeError: 'name'

argparse - 3rd arg only valid for one of two mutually exclusive args?

2021-11-03 Thread Loris Bennett
Hi, With argparse's add_mutually_exclusive_group() I can add mutually exclusive args, but how do I deal with a 3rd arg which only makes sense for one of the mutually exclusive args? More generally I suppose I am interested in having something like [ --foo (--foobar) | --bar (--barfoo) ] if th

  1   2   3   4   5   >