在下面的代码中,我需要打印联系人列表对象。我该怎么做?
# Test.py
class ContactList(list):
def search(self, name):
'''Return all contacts that contain the search value
in their name.'''
matching_contacts = []
for contact in self:
if name in contact.name:
matching_contacts.append(contact)
return matching_contacts
class Contact:
all_contacts = ContactList()
def __init__(self, name, email):
self.name = name
self.email = email
self.all_contacts.append(self)
我创建了 2 个 Contact 对象,但想查看 all_contacts 列表中的所有元素。