我有一个名为test_cases
的类对象列表。每个对象都有一个名为ident
的属性。
我想要遍历列表中的所有对象,并对ident
下的值执行某些操作。
这是我的代码:
class TestCase:
def __init__(self, title, ident, description):
self.title = title
self.ident = ident
self.description = description
test_cases = []
test_cases.append(TestCase(**tc_dict))
i = 0
while i != len(test_cases):
print(test_cases[i].ident)
i += 1
这个方法可以正常工作,但我想问一下,是否有更符合Python编程风格的方法。