Skip to main content
 首页 » 编程设计

python之从键列表中获取对象的最佳方法是什么

2024年11月01日9wuhuacong

我想从我的键列表中提取所有对象。有没有比我现在做的更好的方法?

list_of_objs = [] 
for obj_key in list_of_keys: 
    this_obj = db.get(obj.key) 
    list_of_objs.append(this_obj) 

请您参考如下方法:

根据 documentation db.get 可以接受键列表并在单个批处理中获取它们,这样会快得多。

list_of_objects = db.get(list_of_keys)