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 bo

Re: argparse argument post-processing

2023-11-27 Thread Mats Wichmann via Python-list
On 11/27/23 13:21, Dom Grigonis wrote: Thank you, exactly what I was looking for! One more question following this. Is there a way to have a customisable action? I.e. What if I want to join with space in one case and with coma in another. Is there a way to reuse the same action class? I've w

Re: argparse argument post-processing

2023-11-27 Thread Dom Grigonis via Python-list
Thank you, exactly what I was looking for! One more question following this. Is there a way to have a customisable action? I.e. What if I want to join with space in one case and with coma in another. Is there a way to reuse the same action class? Regards, DG > On 27 Nov 2023, at 21:55, Mats Wi

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 argparse parser = argparse.Argume

Re: argparse argument post-processing

2023-11-27 Thread Chris Angelico via Python-list
On Mon, 27 Nov 2023 at 22:31, 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: This is a single

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

2022-11-28 Thread Chris Angelico
On Tue, 29 Nov 2022 at 12:37, Loris Bennett wrote: > > Mats Wichmann writes: > > > On 11/27/22 16:40, Skip Montanaro wrote: > >> I have a script to which I'd like to add a --version flag. It should print > >> the version number then exit, much in the same way --help prints the help > >> text then

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
Mats Wichmann writes: > On 11/27/22 16:40, Skip Montanaro wrote: >> I have a script to which I'd like to add a --version flag. It should print >> the version number then exit, much in the same way --help prints the help >> text then exits. I haven't been able to figure that out. I always get a >>

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

2022-11-28 Thread Skip Montanaro
Thanks. It occurs to me that instead of providing two special actions ("help" and "version"), it might be worthwhile to provide a standard way of saying, "if present, process this option and exit before considering other details of the command line." Matt's example action works well enough for my n

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

2022-11-28 Thread Weatherby,Gerard
hon-list on behalf of Weatherby,Gerard Date: Sunday, November 27, 2022 at 10:29 PM To: Skip Montanaro , Python Subject: Re: argparse — adding a --version flag in the face of positional args Use two parsers: import argparse import sys vparser = argparse.ArgumentParser(add_help=False) vparser.add

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

2022-11-27 Thread Karen Park
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! Thanks, Karen > On Nov 27, 2022, at 9:34 PM, Skip Montanaro wrote: > >  >> >> >> ummm, hate to say this, but have you checked the docu

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't attempting to be sort of up-to-dat

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.version: print("Version 2.0")

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

2022-11-27 Thread Mats Wichmann
On 11/27/22 16:40, Skip Montanaro wrote: I have a script to which I'd like to add a --version flag. It should print the version number then exit, much in the same way --help prints the help text then exits. I haven't been able to figure that out. I always get a complaint about the required positi

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

2022-11-27 Thread Skip Montanaro
> class VersionAction(argparse.Action): > def __call__(self, parser, namespace, values, option_string): > print(VERSION) > exit() ... > parser.add_argument("-v", "--version", nargs=0, action=VersionAction) Thanks. An action class didn't occur to me. I looked briefly at the code

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 VersionAction(argparse.Act

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 נתי שטרן
Thanks a lot. I will read documentation of enum module בתאריך יום ו׳, 24 ביוני 2022, 14:33, מאת Roel Schroeven ‏< r...@roelschroeven.net>: > 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: > > > > >??? wrot

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)) >>TypeError: 'name' is an invalid keyword a

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) >> > >> > >> >traceback: >> >Traceback (most recent call last): >> >

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 "u:\oracle\RTR.py", line 10, in > >class s

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,name=str(32)) >>> TypeError: 'name' is an invalid k

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 argument for int() > >This does not look like an `a

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 >MAXREPEAT = _NamedIntConstant(32,name=str(32)) >

Re: argparse: delimiter for argparse list arguments

2021-08-03 Thread Roel Schroeven
Jon Ribbens via Python-list schreef op 3/08/2021 om 22:55: >> Loads of git commands do this. e.g. commit, diff, log, status, etc. >> It's not completely unlike what you're describing above, which is >> already supported automatically by argparse. > > Commands like git commit do not use '--' to se

Re: argparse: delimiter for argparse list arguments

2021-08-03 Thread Jon Ribbens via Python-list
On 2021-08-03, Roel Schroeven wrote: > Jon Ribbens via Python-list schreef op 3/08/2021 om 17:48: >> On 2021-08-03, Michael Torrie wrote: >> > On 8/2/21 1:43 PM, Sven R. Kunze wrote: >> >> maybe, I am missing something here but is it possible to specify a >> >> delimiter for list arguments in ar

Re: argparse: delimiter for argparse list arguments

2021-08-03 Thread Chris Angelico
On Wed, Aug 4, 2021 at 7:07 AM Sven R. Kunze wrote: > > It could be but I've seen them used somewhere else. > > I wouldn't bikeshed on this yet, as I haven't found a way to do this so > far. Let's imagine the following parser: > > parser.add_argument('things',action='append') > parser.add_argument

Re: argparse: delimiter for argparse list arguments

2021-08-03 Thread Sven R. Kunze
It could be but I've seen them used somewhere else. I wouldn't bikeshed on this yet, as I haven't found a way to do this so far. Let's imagine the following parser: parser.add_argument('things',action='append') parser.add_argument('stuff',action='append') At least from my point of view, I don

Re: argparse: delimiter for argparse list arguments

2021-08-03 Thread Roel Schroeven
Jon Ribbens via Python-list schreef op 3/08/2021 om 17:48: On 2021-08-03, Michael Torrie wrote: > On 8/2/21 1:43 PM, Sven R. Kunze wrote: >> maybe, I am missing something here but is it possible to specify a >> delimiter for list arguments in argparse: >> >> https://docs.python.org/3/library/a

Re: argparse: delimiter for argparse list arguments

2021-08-03 Thread Jon Ribbens via Python-list
On 2021-08-03, Michael Torrie wrote: > On 8/2/21 1:43 PM, Sven R. Kunze wrote: >> maybe, I am missing something here but is it possible to specify a >> delimiter for list arguments in argparse: >> >> https://docs.python.org/3/library/argparse.html >> >> Usually, '--' is used to separate two lis

Re: argparse: delimiter for argparse list arguments

2021-08-03 Thread Michael Torrie
On 8/2/21 1:43 PM, Sven R. Kunze wrote: > Hi everyone, > > maybe, I am missing something here but is it possible to specify a > delimiter for list arguments in argparse: > > https://docs.python.org/3/library/argparse.html > > Usually, '--' is used to separate two lists (cf. git). I've not seen

Re: argparse: delimiter for argparse list arguments

2021-08-02 Thread Dan Stromberg
Isn't -- usually used to signal the end of options? On Mon, Aug 2, 2021 at 12:52 PM Sven R. Kunze wrote: > Hi everyone, > > maybe, I am missing something here but is it possible to specify a > delimiter for list arguments in argparse: > > https://docs.python.org/3/library/argparse.html > > Usual

Re: argparse support of/by argparse

2021-07-23 Thread Chris Angelico
On Fri, Jul 23, 2021 at 5:34 PM Albert-Jan Roskam wrote: > > >>> [1] https://pypi.org/project/clize/ > > > I use and like docopt (https://github.com/docopt/docopt). Is clize a better > choice? > Not necessarily. Both are good. Explore both, see which one makes more sense. ChrisA -- https://mai

Re: argparse support of/by argparse

2021-07-23 Thread Albert-Jan Roskam
>>> [1] https://pypi.org/project/clize/ I use and like docopt (https://github.com/docopt/docopt). Is clize a better choice? -- https://mail.python.org/mailman/listinfo/python-list

Re: argparse support of/by argparse

2021-07-14 Thread Chris Angelico
On Thu, Jul 15, 2021 at 2:57 PM Dan Stromberg wrote: > > > On Mon, Jul 12, 2021 at 12:34 PM Chris Angelico wrote: >> >> On Tue, Jul 13, 2021 at 5:22 AM lucas wrote: >> > Running CPython on it will raise a TypeError, and running Mypy on it >> > will indicate that no issues were found. >> > >> > I

Re: argparse support of/by argparse

2021-07-14 Thread Dan Stromberg
On Mon, Jul 12, 2021 at 12:34 PM Chris Angelico wrote: > On Tue, Jul 13, 2021 at 5:22 AM lucas wrote: > > Running CPython on it will raise a TypeError, and running Mypy on it > > will indicate that no issues were found. > > > > I was wondering if there is any way for me to have mypy detecting th

Re: argparse support of/by argparse

2021-07-13 Thread lucas
Mmmh, that may work just fine ! Thanks for that idea, ChrisA, i'm looking forward to implement that. Best wishes, --lucas On 12/07/2021 21:33, Chris Angelico wrote: On Tue, Jul 13, 2021 at 5:22 AM lucas wrote: Hello everyone, Let us consider this patch of code: import argparse

Re: argparse support of/by argparse

2021-07-12 Thread Chris Angelico
On Tue, Jul 13, 2021 at 5:22 AM lucas wrote: > > Hello everyone, > > Let us consider this patch of code: > > import argparse > > def parse_cli() -> argparse.Namespace: > parser = argparse.ArgumentParser() > parser.add_argument('n', type=int) > return parser.par

Re: argparse presence of switch

2021-01-12 Thread Greg Ewing
On 13/01/21 7:13 am, Chris Angelico wrote: This is what different actions are for. I'd probably use action="store_true" here; that should mean that args.register will be set to True if "-r" was passed, or False if it wasn't. Yes, otherwise it expects another argument following -r containing a

Re: argparse presence of switch

2021-01-12 Thread David Lowry-Duda
> I want to have an argument's presence only - value is not required. > For example, my program main.py needs to know if "-r" is present when program > is invoked. > So the value command line would be: > (1) python3 main.py -r > or... > (1) python3 main.py > > I tried following: > parser.add_ar

Re: argparse presence of switch

2021-01-12 Thread Chris Angelico
On Wed, Jan 13, 2021 at 5:01 AM Dhimant Patel wrote: > > Its what I searched for on this group. > > I want to have an argument's presence only - value is not required. > For example, my program main.py needs to know if "-r" is present when program > is invoked. > So the value command line would b

Re: ARGPARSE Newbie question

2018-04-17 Thread TUA
Thanks for the pointers! -- https://mail.python.org/mailman/listinfo/python-list

Re: ARGPARSE Newbie question

2018-04-17 Thread paulclarke345
On Tuesday, April 17, 2018 at 7:09:45 PM UTC-5, TUA wrote: > I'd like to create a script that handles a number of verbs with mandatory and > /or optional parameters like listed in the table below. > > Can ARGPARSE do this and how? > > Thanks for all help! > > > > > > Script Verb

Re: argparse epilog call function?

2017-06-30 Thread Rasputin
will you ever post a single .py file which actually works ? all the stuff you post is breaking. -- https://mail.python.org/mailman/listinfo/python-list

Re: argparse epilog call function?

2017-06-27 Thread breamoreboy
On Tuesday, June 27, 2017 at 3:25:10 PM UTC+1, Chris Angelico wrote: > On Wed, Jun 28, 2017 at 12:09 AM, Fox wrote: > > what " -h " are you even talkin bout ? > > > > > > > > > > def Examples(): > > text = """Lots of examples""" > > print(text.format()) > > > > > > > > epilog='where the h

Re: argparse epilog call function?

2017-06-27 Thread Didymus
On Tuesday, June 27, 2017 at 11:47:42 AM UTC-4, Didymus wrote: > On Tuesday, June 27, 2017 at 9:56:13 AM UTC-4, Didymus wrote: > > Greetings, > > > > I might be barking up the wrong tree, but was wondering if there's a way to > > have the argpasre epilog call a function. for example: > > > > epi

Re: argparse epilog call function?

2017-06-27 Thread Didymus
On Tuesday, June 27, 2017 at 9:56:13 AM UTC-4, Didymus wrote: > Greetings, > > I might be barking up the wrong tree, but was wondering if there's a way to > have the argpasre epilog call a function. for example: > > epilog=Examples() > > Where Examples is: > > def Examples(): > text = """L

Re: argparse epilog call function?

2017-06-27 Thread Peter Otten
Didymus wrote: > Greetings, > > I might be barking up the wrong tree, but was wondering if there's a way > to have the argpasre epilog call a function. for example: > > epilog=Examples() > > Where Examples is: > > def Examples(): > text = """Lots of examples""" > print(text.format()) >

Re: argparse epilog call function?

2017-06-27 Thread Chris Angelico
On Wed, Jun 28, 2017 at 12:09 AM, Fox wrote: > what " -h " are you even talkin bout ? > > > > > def Examples(): > text = """Lots of examples""" > print(text.format()) > > > > epilog='where the heck to put a -h ?? ' > > epilog=Examples() List admins, this person has been abusing the p

Re: argparse epilog call function?

2017-06-27 Thread Fox
what " -h " are you even talkin bout ? def Examples(): text = """Lots of examples""" print(text.format()) epilog='where the heck to put a -h ?? ' epilog=Examples() -- https://mail.python.org/mailman/listinfo/python-list

Re: argparse epilog call function?

2017-06-27 Thread Chris Angelico
On Tue, Jun 27, 2017 at 11:55 PM, Didymus wrote: > Greetings, > > I might be barking up the wrong tree, but was wondering if there's a way to > have the argpasre epilog call a function. for example: > > epilog=Examples() > > Where Examples is: > > def Examples(): > text = """Lots of examples"

Re: argparse and subparsers

2016-06-28 Thread Michele Simionato
I did not know about docopt. It is basically the same idea of this recipe I wrote about 12 years ago: https://code.activestate.com/recipes/278844-parsing-the-command-line/?in=user-1122360 Good that it was reinvented :-) -- https://mail.python.org/mailman/listinfo/python-list

RE: argparse and subparsers

2016-06-27 Thread Joseph L. Casale
> Not sure if this fits the bill, or makes sense here, but I came cross > "docopt" which touts itself as a "Command-line interface description > language". I used it in a project and it seems to be pretty easy to use > as well as elegant. It stores the arguments & values as a dictionary, > keyed by

Re: argparse and subparsers

2016-06-27 Thread Sachin Garg
On Monday 27 June 2016 06:28 AM, Steven D'Aprano wrote: > On Monday 27 June 2016 15:34, Lawrence D’Oliveiro wrote: > >> On Monday, June 27, 2016 at 4:56:10 PM UTC+12, Sachin Garg wrote: >> >>> # Set verbose flag >>> verbose = False >>> if arguments['--verbose']: >>> verbose = True >>> elif arg

Re: argparse and subparsers

2016-06-27 Thread Steven D'Aprano
On Monday 27 June 2016 15:34, Lawrence D’Oliveiro wrote: > On Monday, June 27, 2016 at 4:56:10 PM UTC+12, Sachin Garg wrote: > >> # Set verbose flag >> verbose = False >> if arguments['--verbose']: >> verbose = True >> elif arguments['-q']: >> verbose = False > > Don’t you just love code

Re: argparse and subparsers

2016-06-26 Thread Lawrence D’Oliveiro
On Monday, June 27, 2016 at 4:56:10 PM UTC+12, Sachin Garg wrote: > # Set verbose flag > verbose = False > if arguments['--verbose']: > verbose = True > elif arguments['-q']: > verbose = False Don’t you just love code (and commenting) like this... -- https://mail.python.org/mailman/listi

Re: argparse and subparsers

2016-06-26 Thread Sachin Garg
On Sunday 26 June 2016 02:51 PM, Joseph L. Casale wrote: > I have some code where sys.argv is sliced up and manually fed to discrete > argparse > instances each with a single subparser. The reason the discrete parsers all > having a > single subparser was to make handling the input simpler, the f

Re: argparse and subparsers

2016-06-26 Thread Lawrence D’Oliveiro
On Monday, June 27, 2016 at 6:56:41 AM UTC+12, Joseph L. Casale wrote: > This has become unmaintainable as the manual slicing is always subject > to a new case by where a parser has a positional, switch or optional > parameter for example. Also, since argv is grouped by subparser > specifiers, if a

Re: argparse

2016-03-12 Thread Sven R. Kunze
On 12.03.2016 00:18, Fillmore wrote: Playing with ArgumentParser. I can't find a way to override the -h and --help options so that it provides my custom help message. I remember everything being a lot easier using argh instead of argparse. https://pypi.python.org/pypi/argh#examples The doc

Re: argparse

2016-03-11 Thread Ian Kelly
On Fri, Mar 11, 2016 at 4:18 PM, Fillmore wrote: > > Playing with ArgumentParser. I can't find a way to override the -h and > --help options so that it provides my custom help message. > > -h, --help show this help message and exit > > Here is what I am trying: > > parser = argparse.Argu

Re: argparse

2016-03-11 Thread Fillmore
On 3/11/2016 6:26 PM, Larry Martell wrote: am I missing something obvious? https://docs.python.org/2/library/argparse.html#usage you rock! -- https://mail.python.org/mailman/listinfo/python-list

Re: argparse

2016-03-11 Thread Larry Martell
On Fri, Mar 11, 2016 at 6:18 PM, Fillmore wrote: > > > Playing with ArgumentParser. I can't find a way to override the -h and --help > options so that it provides my custom help message. > > -h, --help show this help message and exit > > Here is what I am trying: > > parser = argparse.A

Re: argparse

2016-03-11 Thread Bob Gailer
On Mar 11, 2016 6:20 PM, "Fillmore" wrote: > > > Playing with ArgumentParser. I can't find a way to override the -h and --help options so that it provides my custom help message. > > -h, --help show this help message and exit > > Here is what I am trying: > > parser = argparse.ArgumentPa

Re: [argparse] optional parameter without --switch

2015-11-24 Thread Peter Otten
c.bu...@posteo.jp wrote: > I want to call (on bash) a Python script in this two ways without any > error. > > ./arg.py > ./arg.py TEST > > It means that the parameter (here with the value `TEST`) should be > optional. With argparse I only know a way to create optional paramters > when th

Re: argparse: use of double dash to separate options and positional arguments

2015-11-06 Thread Random832
Peter Otten <__pete...@web.de> writes: > I'm not sure about this one; one purpose of REMAINDER is to pass on the > unprocessed arguments to another program/script, and this might follow the > same convention. Should > > parser.add_argument('-v', '--verbose', action='store_true') > parser.add_arg

Re: argparse: use of double dash to separate options and positional arguments

2015-11-06 Thread Peter Otten
Amit Ramon wrote: > Peter Otten <__pete...@web.de> [2015-11-06 11:57 +0100]: > > >>> >>> For example, with the above code >>> >>> my_prog -v hello world >>> >>> works well, but >>> >>> my_prog -v -x hello world >>> >>> Fails with an error message 'error: unrecognized arguments: -x'. >> >

Re: argparse: use of double dash to separate options and positional arguments

2015-11-06 Thread Amit Ramon
Peter Otten <__pete...@web.de> [2015-11-06 11:57 +0100]: For example, with the above code my_prog -v hello world works well, but my_prog -v -x hello world Fails with an error message 'error: unrecognized arguments: -x'. This looks like a bug to me. Please report it on bug.python.

Re: argparse: use of double dash to separate options and positional arguments

2015-11-06 Thread Peter Otten
Amit Ramon wrote: > Hello, > > I'm trying to use argparse in a program that gets some options and > positional arguments. I want to collect all the positional arguments > in a single argument using the REMAINDER option to add_argument() as > shown bellow: > > parser = argparse.ArgumentParser

Re: argparse question

2014-02-22 Thread Larry Hudson
On 02/22/2014 03:58 AM, Peter Otten wrote: Larry Hudson wrote: I have been reading the argparse section of the 3.3 docs, and running all the example code. But in section 16.4.2.6. for the formatter_class, the second example in that section illustrating RawDescriptionHelpFormatter, the example

Re: argparse question

2014-02-22 Thread Peter Otten
Larry Hudson wrote: > I have been reading the argparse section of the 3.3 docs, and running all > the example code. > > But in section 16.4.2.6. for the formatter_class, the second example in > that section illustrating RawDescriptionHelpFormatter, the example code > is: > > parser = argparse.Ar

Re: argparse action on default values

2014-01-09 Thread Chris Angelico
On Thu, Jan 9, 2014 at 5:20 AM, Florian Lindner wrote: > def norm_path(*parts): > """ Returns the normalized, absolute, expanded and joined path, assembled > of all parts. """ > parts = [ str(p) for p in parts ] > return os.path.abspath(os.path.expanduser(os.path.join(*parts))) Apolo

Re: argparse action on default values

2014-01-08 Thread Terry Reedy
On 1/8/2014 1:20 PM, Florian Lindner wrote: I use argparse from Python 3.3.3 with a custom action that normalizes path arguments: This works fine when there is actually a --config=path supplied. But it's not being applied on default arguments. This behavior is how I interpret the doc. http:

Re: argparse action on default values

2014-01-08 Thread Peter Otten
Florian Lindner wrote: > I use argparse from Python 3.3.3 with a custom action that normalizes path arguments: > > http://docs.python.org/3/library/argparse.html#action > > def norm_path(*parts): > """ Returns the normalized, absolute, expanded and joined path, assembled of all parts. """

Re: argparse feature request

2013-11-22 Thread Robert Kern
On 2013-11-22 18:15, Neal Becker wrote: Robert Kern wrote: On 2013-11-22 16:52, Neal Becker wrote: Robert Kern wrote: On 2013-11-22 14:56, Neal Becker wrote: I use arparse all the time and find it serves my needs well. One thing I'd like to see. In the help message, I'd like to automatica

Re: argparse feature request

2013-11-22 Thread Neal Becker
Robert Kern wrote: > On 2013-11-22 16:52, Neal Becker wrote: >> Robert Kern wrote: >> >>> On 2013-11-22 14:56, Neal Becker wrote: I use arparse all the time and find it serves my needs well. One thing I'd like to see. In the help message, I'd like to automatically add the default

Re: argparse feature request

2013-11-22 Thread Robert Kern
On 2013-11-22 16:52, Neal Becker wrote: Robert Kern wrote: On 2013-11-22 14:56, Neal Becker wrote: I use arparse all the time and find it serves my needs well. One thing I'd like to see. In the help message, I'd like to automatically add the default values. What I'd like to see is: --siz

Re: argparse feature request

2013-11-22 Thread Neal Becker
Robert Kern wrote: > On 2013-11-22 14:56, Neal Becker wrote: >> I use arparse all the time and find it serves my needs well. One thing I'd >> like >> to see. In the help message, I'd like to automatically add the default >> values. >> >> For example, here's one of my programs: >> >> python3 te

Re: argparse feature request

2013-11-22 Thread Robert Kern
On 2013-11-22 14:56, Neal Becker wrote: I use arparse all the time and find it serves my needs well. One thing I'd like to see. In the help message, I'd like to automatically add the default values. For example, here's one of my programs: python3 test_freq3.py --help usage: test_freq3.py [-

Re: argparse - specify order of argument parsing?

2013-08-31 Thread Peter Otten
Eduardo Alvarez wrote: > When using argparse, is there a way to specify in what order arguments > get parsed? I am writing a script whose parameters can be modified in > the following order: > > Defaults -> config file -> command-line switches. > > However, I want to give the option of specifyin

Re: argparse - specify order of argument parsing?

2013-08-31 Thread Cameron Simpson
On 31Aug2013 14:17, Terry Reedy wrote: | On 8/31/2013 2:13 PM, Terry Reedy wrote: | >On 8/31/2013 1:11 PM, Eduardo Alvarez wrote: | >>When using argparse, is there a way to specify in what order arguments | >>get parsed? | > | >I expect argparse to forward iterate the sequence of arguments that it

Re: argparse - specify order of argument parsing?

2013-08-31 Thread Terry Reedy
On 8/31/2013 2:13 PM, Terry Reedy wrote: On 8/31/2013 1:11 PM, Eduardo Alvarez wrote: When using argparse, is there a way to specify in what order arguments get parsed? I expect argparse to forward iterate the sequence of arguments that it receives. Aside from the environment variable soluti

Re: argparse - specify order of argument parsing?

2013-08-31 Thread Terry Reedy
On 8/31/2013 1:11 PM, Eduardo Alvarez wrote: When using argparse, is there a way to specify in what order arguments get parsed? I expect argparse to forward iterate the sequence of arguments that it receives. I am writing a script whose parameters can be modified in the following order: De

Re: argparse - specify order of argument parsing?

2013-08-31 Thread Tim Chase
On 2013-08-31 13:11, Eduardo Alvarez wrote: > When using argparse, is there a way to specify in what order > arguments get parsed? I am writing a script whose parameters can be > modified in the following order: > > Defaults -> config file -> command-line switches. > > However, I want to give the

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-06 Thread Francois Lafont
Le 07/08/2013 01:18, Francois Lafont a écrit : > For the inheritance of common options, I'll used something like > that (even if I prefer the oriented object side of the argparse > module): But I admit that this is a very simple and intelligent module. ;-) -- François Lafont -- http://mail.pyt

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-06 Thread Francois Lafont
Hi, On relfection, it's clear that: 1. the "(-a -b VALUE-B | -c -d VALUE-D)" syntax is not implemented by the argparse module; 2. and get this syntax with "argparse + hacking" is not very clean. So, finally I'll use the docopt module version 0.6.1. For the inheritance of common options, I'll us

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Francois Lafont
Le 05/08/2013 22:01, Rafael Durán Castañeda a écrit : > I think you are looking for exclusive groups: > > http://docs.python.org/2.7/library/argparse.html#argparse.add_mutually_exclusive_group Yes... but no. The doc explains you can do this: my-script (-b VALUE-B | -d VALUE-D) ie mutally excl

RE: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Joseph L. Casale
> I think you are looking for exclusive groups: > > http://docs.python.org/2.7/library/argparse.html#argparse.add_mutually_excl > usive_group No. That links first doc line in that method shows the very point we are all discussing: "Create a mutually exclusive group. argparse will make sure that

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Francois Lafont
Le 05/08/2013 16:11, Miki Tebeka a écrit : > You can probably do something similar using sub commands > (http://docs.python.org/2/library/argparse.html#sub-commands). Yes, but this is not the same syntax. I want this syntax : my-script (-a -b VALUE-B | -c -d VALUE-D) I don't want this syntax:

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Rafael Durán Castañeda
El 04/08/13 04:10, Francois Lafont escribió: Hi, Is it possible with argparse to have this syntax for a script? my-script (-a -b VALUE-B | -c -d VALUE-D) I would like to do this with the argparse module. Thanks in advance. I think you are looking for exclusive groups: http://docs.python.o

RE: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Joseph L. Casale
> You can probably do something similar using sub commands > (http://docs.python.org/2/library/argparse.html#sub-commands). The problem here is that argparse does not pass the subparser into the parsed args and shared args between subparsers need to be declared each time. Come execution time, when

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-05 Thread Miki Tebeka
> Is it possible with argparse to have this syntax for a script? > my-script (-a -b VALUE-B | -c -d VALUE-D) > > I would like to do this with the argparse module. You can probably do something similar using sub commands (http://docs.python.org/2/library/argparse.html#sub-commands). -- http://mai

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-04 Thread Joshua Landau
On 5 August 2013 03:05, Francois Lafont wrote: > Hello, > > Up. ;-) > > Le 04/08/2013 04:10, Francois Lafont a écrit : > > > Is it possible with argparse to have this syntax for a script? > > > > my-script (-a -b VALUE-B | -c -d VALUE-D) > > > > I would like to do this with the argparse module. >

Re: [argparse] mutually exclusive group with 2 sets of options

2013-08-04 Thread Francois Lafont
Hello, Up. ;-) Le 04/08/2013 04:10, Francois Lafont a écrit : > Is it possible with argparse to have this syntax for a script? > > my-script (-a -b VALUE-B | -c -d VALUE-D) > > I would like to do this with the argparse module. > > Thanks in advance. I have found this post: https://groups.goo

Re: argparse -- mutually exclusive sets of arguments?

2012-11-23 Thread Ian Kelly
On Fri, Nov 23, 2012 at 11:46 AM, Roy Smith wrote: > My command either takes two positional arguments (in which case, both > are required): > > $ command foo bar > > or the name of a config file (in which case, the positional arguments > are forbidden): > > $ command --config file > > How can I re

Re: argparse -- mutually exclusive sets of arguments?

2012-11-23 Thread Joshua Landau
On 23 November 2012 18:46, Roy Smith wrote: > My command either takes two positional arguments (in which case, both > are required): > > $ command foo bar > > or the name of a config file (in which case, the positional arguments > are forbidden): > > $ command --config file > > How can I represen

Re: argparse -- mutually exclusive sets of arguments?

2012-11-23 Thread Terry Reedy
On 11/23/2012 1:46 PM, Roy Smith wrote: My command either takes two positional arguments (in which case, both are required): $ command foo bar or the name of a config file (in which case, the positional arguments are forbidden): $ command --config file How can I represent this with argparse;

Re: argparse localization support

2012-08-26 Thread Peter Otten
Kwpolska wrote: > I am using argparse in my project. I want to localize it, but it > seems to be impossible to change some things. See this, for example: > > usage: trash [-h] [-V] [-e] [-l] [-r] [-v] [-w] [PLIK [PLIK ...]] > > Trashman — menedżer śmietnika XDG w Pythonie. > > positional argu

Re: argparse limitations

2012-07-31 Thread Benoist Laurent
> The standard way, however, is to have a parser that takes the first > non-option argument as a subcommand name and parses the remaining arguments > according to that subcommand. Your command line users are more likely to be > able to understand how to use the program if it works that way. I'l

Re: argparse limitations

2012-07-31 Thread Oscar Benjamin
On 31 July 2012 13:51, Benoist Laurent wrote: > > Le Jul 31, 2012 à 1:45 PM, Oscar Benjamin a écrit : > > > > On 31 July 2012 12:03, Benoist Laurent wrote: > >> Finally. >> >> The code I proposed doesn't work in this case: if you add any positional >> argument to one of the subparsers, then the

  1   2   >