python - parser - Ejemplo de uso del programa de impresión con módulo argparse
parser python example (1)
Utilice parser.epilog para mostrar algo después del texto -h generado.
parser = argparse.ArgumentParser(
description=''My first argparse attempt'',
epilog=''Example of use'')
output = parser.parse_args()
huellas dactilares:
My first argparse attempt
optional arguments:
-h, --help show this help message and exit
Example of use
Estoy tratando de aprender a usar el módulo argparse de python. Actualmente mi script en python es:
parser = argparse.ArgumentParser(description=''My first argparse attempt'',
add_help=True)
parser.add_argument("-q", action ="store", dest=''argument'',
help="First argument")
output = parser.parse_args()
Y da la salida como:
usage: test.py [-h] [-q ARGUMENT]
My first argparse attempt
optional arguments:
-h, --help show this help message and exit
-q ARGUMENT First argument
Ahora, supongamos que quiero que mi argumento -h or --help imprima un usage example . Me gusta,
Usage: python test.py -q "First Argument for test.py"
Mi propósito es imprimir el ejemplo de uso anterior junto con el contenido predeterminado del argumento -h para que el usuario pueda tener una idea básica de cómo usar el test.py python test.py
Entonces, ¿esta funcionalidad está incorporada en el módulo argparse ? Si no es así, ¿cuál es la forma correcta de abordar este problema?