Ordenar argparse ayuda alfabéticamente
Estoy usando la función argparse de Python (2.7) y me gustaría ordenar automáticamente la ayuda que produce alfabéticamente por opción.
Por defecto, las entradas de ayuda se ordenan en el orden en que se agregan *, como en:
p = argparse.ArgumentParser(description='Load duration curves and other plots')
p.add_argument('--first', '-f', type=int, default=1, help='First Hour')
p.add_argument('--dur', '-d', type=int, default=-1, help='Duration in Hours. Use -1 for all')
p.add_argument('--title', '-t', help='Plot Title (for all plots), default=file name')
p.add_argument('--interp', '-i', action="store_true", default=True,
help='Use linear interpolation for smoother curves')
...
args = p.parse_args()
Que cuando se llama comopython script -h
produce:
usage: script.py [-h] [--first FIRST] [--dur DUR] [--title TITLE] [--interp]
Load duration curves and other plots
optional arguments:
-h, --help show this help message and exit
--first FIRST, -f FIRST
First Hour
--dur DUR, -d DUR Duration in Hours. Use -1 for all
--title TITLE, -t TITLE
Plot Title (for all plots), default=file name
--interp, -i Use linear interpolation for smoother curves
¿Es posible clasificarlos automáticamente en orden alfabético? Esto sería dur, primero, h, interp, título.
* Obviamente, la solución consiste en mantener manualmente agregando entradas usando p.add_argument en orden alfabético agregado, pero estoy tratando de evitar hacerlo.