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

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

问题描述

我想使用类继承来构建sunburnt(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')?

推荐答案

使用双星(又名 double-splat?)operator:

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

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

相当于

func(type='Event')

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

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