简体   繁体   English

将列表传递给一个 kwargs

[英]Passing a list into one kwargs

The final idea is to start my python program with a command like: python.exe -m myProgram execute --tags arg1 arg2 arg3 I'm trying to get "arg_1", "arg_2", ..., "arg_n" (with n unknown) inside a list and access all of them thanks to "tags"最后的想法是使用如下命令启动我的 python 程序: python.exe -m myProgram execute --tags arg1 arg2 arg3我正在尝试获取“arg_1”、“arg_2”、...、“arg_n”(使用n 未知)在列表中并通过“标签”访问所有这些

I tried some ways like:我尝试了一些方法,例如:

def run(self, **kwargs) -> None:
    tags = []
    for arg in kwargs.values():
        tags = tags.append(kwargs.get("tags", None))
    print(tags)

Or:或者:

def run(self, **kwargs) -> None:
    tags = kwargs.get("tags", None)

But I can't get expected result.但我无法得到预期的结果。 Should I change my command or does it exist a way to get tags like a list?我应该更改我的命令还是是否存在获取列表等标签的方法? Please, any help?请问,有什么帮助吗? Thank you谢谢

Ok, I found how to do: python.exe -m myProgram execute --tags=[arg1,arg2,arg3] This format created the list I wanted to send to my program.好的,我找到了方法: python.exe -m myProgram execute --tags=[arg1,arg2,arg3]这种格式创建了我想发送到我的程序的列表。 Anyway, your links was interesting to read.不管怎样,你的链接读起来很有趣。 Thanks again.再次感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM