使用属性筛选列表
mexp的Python项目详细描述
您可以使用mexp帮助使用find and find\u mactch properties条件的任何元素筛选对象列表
示例:
文件test_mexp.py
:
from car_class import Car
from mexp import *
if __name__ == "__main__":
listTesti = []
listTesti.append(Car('Jack', 'benlalla', True, 1))
listTesti.append(Car('Jack2', 'elarrs', False, 5))
listTesti.append(Car('Marc', 'roro', False, 2))
result = find(listTesti, lname = 'roro')
print(result)
文件car_class.py
find_any(列出_object,**kwargs)
Args:
list_of_object: provide a list of objects you want to filter
kwargs: properties with values you want to use as filter
Returns:
A filtered list of objects that match any of the filter properties
def find(列出_对象,**kwargs):
Args:
list_of_object: provide a list of objects you want to filter
kwargs: properties with values you want to use as filter
Returns:
A filtered list of objects that match the filter properties
- 项目
标签: