将 Python dict 转换为 kwargs? [英] Converting Python dict to kwargs?

查看:34
本文介绍了将 Python dict 转换为 kwargs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用类继承来构建晒伤(solr 接口)的查询,因此将键值对添加到一起.sunburnt 接口采用关键字参数.如何将 dict ({'type':'Event'}) 转换为关键字参数 (type='Event')?

I want to build a query for sunburnt(solr interface) using class inheritance and therefore adding key - value pairs together. The sunburnt interface takes keyword arguments. How can I transform a dict ({'type':'Event'}) into keyword arguments (type='Event')?

推荐答案

使用 双星(又名双splat?) 运算符:

Use the double-star (aka double-splat?) operator:

func(**{'type':'Event'})

相当于

func(type='Event')

这篇关于将 Python dict 转换为 kwargs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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