> 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
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
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 parsing doesn't work anymore.
> The reason seems to be
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 parsing doesn't work anymore.
> The reason seems to be that argparse thinks the last argument of the first
> parser i
Finally.
The code I proposed doesn't work in this case: if you add any positional
argument to one of the subparsers, then the parsing doesn't work anymore.
The reason seems to be that argparse thinks the last argument of the first
parser is the last but one argument.
Hence, if a subparser takes
Really sorry about that.
So, for the community, below is the full code for a tool that behaves like a
Unix standard tool.
It takes in argument the files to process and a command.
"""Just to setup a command-line parser that acts just like a unix
standard tool."""
import argparse
import sys
def
On Jul 31, 2012 10:32 AM, "Benoist Laurent" wrote:
>
> Well sorry about that but it seems I was wrong.
> It was Friday evening and I guess I've not been careful.
>
> Actually when you specify nargs="?", the doc says "One argument will be
consumed from the command line if possible, and produced as
Well sorry about that but it seems I was wrong.
It was Friday evening and I guess I've not been careful.
Actually when you specify nargs="?", the doc says "One argument will be
consumed from the command line if possible, and produced as a single item".
So you can't pass several arguments to the
Yes basically looks like you get it.
I have to further test it but my first impression is that it's correct.
So actually the point was to use nargs="?".
Thank you very much.
Ben
Le Jul 27, 2012 à 5:44 PM, Peter Otten a écrit :
> Benoist Laurent wrote:
>
>> I'm impletting a tool in Python.
On Fri, Jul 27, 2012 at 10:26 AM, Ian Kelly wrote:
> It may be a bit awkward having to type "-i" once per file in the
> command line, but it does clear up the ambiguity.
Or you could bite the bullet and make the input files argument part of
the subparser, which you may find ugly, but I believe it
On Fri, Jul 27, 2012 at 9:19 AM, Benoist Laurent wrote:
> That's the solution I came to.
> But I'm not very happy with this since I can definitively not make my
> program act as a standard unix tool.
> Any other solution?
I don't understand; that's pretty much the same way that standard unix
tool
Benoist Laurent wrote:
> I'm impletting a tool in Python.
> I'd like this tool to behave like a standard unix tool, as grep for
> exemple. I chose to use the argparse module to parse the command line and
> I think I'm getting into several limitations of this module.
>
>> First Question.
> How can
Le Jul 27, 2012 à 4:43 PM, Oscar Benjamin a écrit :
>
>
> On 27 July 2012 15:26, Benoist Laurent wrote:
> Hi,
>
> I'm impletting a tool in Python.
> I'd like this tool to behave like a standard unix tool, as grep for exemple.
> I chose to use the argparse module to parse the command line and
On 27 July 2012 15:26, Benoist Laurent wrote:
> Hi,
>
> I'm impletting a tool in Python.
> I'd like this tool to behave like a standard unix tool, as grep for
> exemple.
> I chose to use the argparse module to parse the command line and I think
> I'm getting into several limitations of this modul
Hi,
I'm impletting a tool in Python.
I'd like this tool to behave like a standard unix tool, as grep for exemple.
I chose to use the argparse module to parse the command line and I think I'm
getting into several limitations of this module.
> First Question.
How can I configure the the ArgumentPa
15 matches
Mail list logo