Dynamic Keyword Arguments in Python?

前端 未结 4 1827
灰色年华
灰色年华 2020-12-01 10:24

Does python have the ability to create dynamic keywords?

For example:

qset.filter(min_price__usd__range=(min_price, max_price))

I w

4条回答
  •  感情败类
    2020-12-01 10:58

    Yes, It does. Use **kwargs in a function definition.

    Example:

    def f(**kwargs):
        print kwargs.keys()
    
    
    f(a=2, b="b")     # -> ['a', 'b']
    f(**{'d'+'e': 1}) # -> ['de']
    

    But why do you need that?

提交回复
热议问题