逗号分隔的输入,而不是argparse的空格分隔的输入 [英] Comma separated inputs instead of space separated inputs for argparse

查看:171
本文介绍了逗号分隔的输入,而不是argparse的空格分隔的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 argparse 从命令行接收输入以运行我的脚本。

I'm using argparse to receive inputs from the command line to run my script.

我当前输入字符串如下:

My current input string looks like this:

path> python <\filename\\> -t T1 T2 T3 -f F1 F2

在argparse中是否有一个参数,而不是分隔输入

Is there a parameter in argparse such that instead of separating inputs by space, I can separate them by commas?

换句话说:

path> python <\filename\\> -t T1,T2,T3 -f F1,F2


推荐答案

argparse 中没有此类功能。

替代方法:


  • args进行后处理名称空间并手动拆分/解析值

  • 定义自定义 action 并手动拆分/解析值

  • 定义自定义类型并手动拆分/解析值

  • 子类 ArgumentParser 并自定义 ArgumentParser.convert_arg_line_to_args

  • post-process the args namespace and split/parse the values manually
  • define a custom action and split/parse the values manually
  • define a custom type and split/parse the values manually
  • subclass ArgumentParser and customise ArgumentParser.convert_arg_line_to_args

这篇关于逗号分隔的输入,而不是argparse的空格分隔的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆