相关疑难解决方法(0)

解构 - 绑定字典内容

I am trying to 'destructure' a dictionary and associate values with variables names after its keys. Something like

params = {'a':1,'b':2}
a,b = params.values()
Run Code Online (Sandbox Code Playgroud)

But since dictionaries are not ordered, there is no guarantee that params.values() will return values in the order of (a, b). Is there a nice way to do this?

python sorting dictionary

45
推荐指数
10
解决办法
2万
查看次数

python中的动态变量名

我想调用带有字段名称过滤器的查询,在运行时我不知道...不确定如何构造变量名称......或者我可能已经累了.

field_name = funct()
locations = Locations.objects.filter(field_name__lte=arg1)
Run Code Online (Sandbox Code Playgroud)

如果funct()返回name将等于

locations = Locations.objects.filter(name__lte=arg1)
Run Code Online (Sandbox Code Playgroud)

不知道该怎么做......

python django

4
推荐指数
1
解决办法
2366
查看次数

在Python中从字符串创建变量

在Python中可能具有以下内容:

>>> vars = {'a': 5}
>>> makevars(vars)
>>> print a
5
Run Code Online (Sandbox Code Playgroud)

因此,makevars将字典转换为变量.(一般来说这叫什么?)

python variables

1
推荐指数
1
解决办法
2347
查看次数

标签 统计

python ×3

dictionary ×1

django ×1

sorting ×1

variables ×1