在 -h 中显示选项的选择。在带有 argparse 的 python 中使用可选的命令行参数时
Show choices of option in -h. When using and optional command line argument in python with argparse
所以我想用一个可选参数启动我的程序,该参数具有预定义的选项,选项显示在 -h 屏幕中。以便用户知道可以选择哪个选项。
parser = argparse.ArgumentParser(description="This is a program which creates a prediction model for the boston housing dataset.")
parser.add_argument("Model", help="Choose which model you want to use for prediction.",
type=str, choices=["linear_regression", "polynomial_regression"])
parser.add_argument("--fd", metavar="FEEDBACK", help="Set how much feedback you want.",
type=str, choices=["full", "immediate", "weak"])
args = parser.parse_args()
问题是当我使用 -h 启动程序时,我没有看到 --fd 的可用选项。我怎样才能改变它,以便用户可以看到 --fd 的可用选项,就像图片中显示的模型选项一样?
所以我想用一个可选参数启动我的程序,该参数具有预定义的选项,选项显示在 -h 屏幕中。以便用户知道可以选择哪个选项。
parser = argparse.ArgumentParser(description="This is a program which creates a prediction model for the boston housing dataset.")
parser.add_argument("Model", help="Choose which model you want to use for prediction.",
type=str, choices=["linear_regression", "polynomial_regression"])
parser.add_argument("--fd", metavar="FEEDBACK", help="Set how much feedback you want.",
type=str, choices=["full", "immediate", "weak"])
args = parser.parse_args()
问题是当我使用 -h 启动程序时,我没有看到 --fd 的可用选项。我怎样才能改变它,以便用户可以看到 --fd 的可用选项,就像图片中显示的模型选项一样?