3 回答
TA贡献1801条经验 获得超16个赞
您可以使用参数解包将指定的参数指定为字典,args如果则不存在launch[4] is None,例如:
procs = []
for key, launch in zip(procinfos.keys(), launches):
params = {"name": key, "target": launch[0]}
if launch[4] is not None:
params["args"] = launch[1:]
procs.append(Process(**params))
TA贡献1848条经验 获得超10个赞
的默认值args是一个空的元组,不是None:
launch[1:] if launch[4] is not None else ()
我真的会避免编写三行单行代码。常规for循环没有错:
processes = []
for key, launch in zip(procinfos, launches):
args = launch[1:] if launch[4] is not None else ()
process = Process(name=key, target=launch[0], args=args)
processes.append(process)
TA贡献1982条经验 获得超2个赞
替换None为空的元组:()
procs = [Process(name=key, target=launch[0],
args=launch[1:] if launch[4] is not None else ())
for key, launch in zip(procinfos.keys(), launches)]
添加回答
举报