当我尝试使用以下方法将 namedtuple 转换为字典 [python 2.7.12] 时,namedtuple._as_dict()发现比第一种方法慢 10 倍以上。谁能告诉我这背后的原因是什么?
In [1]: Container = namedtuple('Container', ['name', 'date', 'foo', 'bar'])
In [2]: c = Container('john','10-2-2017',20.78,'python')
In [3]: %timeit dict(name=c.name,date=c.date,foo=c.foo,bar=c.bar)
The slowest run took 7.57 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 536 ns per loop
In [4]: %timeit c._asdict()
The slowest run took 4.84 times longer than the fastest. This could mean that an intermediate result is being …Run Code Online (Sandbox Code Playgroud) 我的虚拟机中有几个虚拟机。我希望在不同的组中查看它们,而不是 ui 中的单个列表。所以特定环境的所有机器将被组合在一起。是否有可能在 vagrantfile 中提及组名?