Pergunta

Instead of this:

usage: installer.py [-h] [-v] dir

I would like to have this:

usage: installer.py dir [-h] [-v]

Is there a way of specifying the position of positional arguments?

Foi útil?

Solução

If you set a positional argument, this argument can be consumed in either way, so you still can have

installer.py dir [-h] [-v]

And dir would be consumed, this is very similar to the example in the ArgParse documentation: http://docs.python.org/library/argparse.html#example

Outras dicas

From the argparse Documentation

By default, ArgumentParser calculates the usage message from the arguments it contains:

usage: PROG [-h] [--foo [FOO]] bar [bar ...]

The default message can be overridden with the usage= keyword argument:

>> parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]')

usage: PROG [options]
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top