私はPythonの(2.7)argparse機能を使用しており、オプションでアルファベット順に生成されたヘルプを自動的にソートしたいと考えています。アルファベット順でargparseヘルプをソート
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
それが自動的にアルファベット順にソートすることが可能です:python script -h
として呼び出されたときに生成
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()
:デフォルトのヘルプ項目によって
はのように、彼らは*追加された順にソートされています代わりに?これは、まず、h、interp、titleとなるでしょう。
*明らかに、回避策は、アルファベット順でp.add_argumentを使用してエントリを追加して手動で管理することですが、これを回避しようとしています。
私はあなたがp.show_helpか何かをフックして、手作業でargリストを解析できると思います...私はそれについてドキュメントを見つけることができるかどうかを見ていきます... –