python - 打印组合成连续字符串的输入字符串
问题描述
有人可以帮我为 cli 编写一个参数,以便它可以将“输入字符串”打印为组合的连续字符串吗?我如何使它成为真正的代码来做我想做的事?
parser.add_argument('-c','--combine', action='store', dest='store_combined', help='Print input strings combined in a continuous string')
args = parser.parse_args()
所以如果我运行 $ python HW3_cli.py -c
These Strings Get Concatenated 然后我得到TheseStringsGetConcatenated
一个打印。
我还可以打印每个字符串的长度吗?
解决方案
您可以尝试将字符串放在引号中:
python HW3_cli.py -c "These Strings Get Concatenated"
然后在您的代码中,您可以像这样按空格分隔:
args = parser.parse_args()
print(args.store_combined.split())
#['These', 'Strings', 'Get', 'Concatenated']
推荐阅读
- python - 将日志级别设置为处理程序在 python 中不起作用
- amazon-web-services - 无法在 AWS ubuntu 上安装任何东西
- python-3.x - 文本分类器训练数据未通过 spacy debug-data CLI 正确加载
- laravel - 如何使用 Laravel 模型保存和检索 base64 编码数据
- azure - 如何将部门添加到 Azure AD 令牌
- php - Symfony 3.4 为什么 Formtype 的 CollectionType 不发布值
- c - 当流不为 0 时 fgetc() 返回 EOF
- javascript - 在java脚本中循环有限的对象
- javascript - 需要为我的简单 ToDoList 添加一个 localStorage
- javascript - 在 Django 中搜索 javascript