Python-argparse对于Python中的两个可能列表,使用命令触发其中一个
我想添加一个参数,这样当用户选择-cta时,它将使用chargetype_a中的列表(其中显示“信用”、“退款”),如果用户选择-ctb,它将使用chargetype_b中的列表(其中显示“信用”、“退款”、“私人费率卡折扣”)。我不确定这是否可以在一个过滤器中完成(请参阅最后一行,这是命令应该去的地方),但是否有其他建议可以在这两个列表中选择进入过滤器Python-argparse对于Python中的两个可能列表,使用命令触发其中一个,python,argparse,Python,Argparse,我想添加一个参数,这样当用户选择-cta时,它将使用chargetype_a中的列表(其中显示“信用”、“退款”),如果用户选择-ctb,它将使用chargetype_b中的列表(其中显示“信用”、“退款”、“私人费率卡折扣”)。我不确定这是否可以在一个过滤器中完成(请参阅最后一行,这是命令应该去的地方),但是否有其他建议可以在这两个列表中选择进入过滤器 parser.add_argument('-cta','--chargetype_a', dest='chargetype_a', defa
parser.add_argument('-cta','--chargetype_a', dest='chargetype_a',
default=None, required=True,
help='this is the charge type that does not include
credits or refunds')
parser.add_argument('-ctb','--chargetype_b', dest='chargetype_b',
default=None, required=True,
help='this is the charge type that does not include
credits, refunds, discounts')
args = parser.parse_args()
chargetype_a = ('Credit', 'Refund')
chargetype_b = ('Credit', 'Refund', 'Private Rate Card Discount')
token = None
while True:
if token:
kwargs = {'NextPageToken': token}
else:
kwargs = {}
data = cd.get_cost(
TimePeriod={
'Start': date_start,
'End': date_end
},
Filter={'Not':{'Dimensions': {'Key': 'RECORD_TYPE','Values': input('--cta or --ctb')}}}, **kwargs)
添加打印(args)
以查看解析器生成的内容。在当前定义中,您必须在命令行python yourscrpt.py-cta something-ctb sometherstring
上提供。如果您不想提供这些字符串,请考虑使用<代码> action =“StureStruts”< /Cord>参数。