Dynamic Keyword Arguments in Python?

前端 未结 4 1824
灰色年华
灰色年华 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:43

    If I understand what you're asking correctly,

    qset.filter(**{
        'min_price_' + selected_currency + '_range' :
        (min_price, max_price)})
    

    does what you need.

提交回复
热议问题