我正在学习 python 的 win32com ,我遇到了一个奇怪的问题。
我正在尝试导出字典列表中的 Outlook 联系人。我的代码与 win32com.client.Dispatch("Outlook.Application) 完美配合。但它使用 win32com.client.gencache.EnsureDispatch("Outlook.Application) 返回 0 个联系人,这应该更快、更“安全”。这是我的代码:
class MapiImport():
def __init__(self):
self.olApp = win32com.client.Dispatch("Outlook.Application")
self.namespace = self.olApp.GetNamespace(u"MAPI")
# olFolderContacts = 10 :
self.mapiContacts = self.namespace.GetDefaultFolder(10).Items
def getContacts(self, *fields):
contacts = []
# Class == 40 is ContactItem
# Class == 69 is DistListItem
# Exclude ditribution list and others objects != ContactItem
for contact in filter(lambda x: x.Class == 40,self.mapiContacts) :
if not fields :
ctact = dict((x.Name,x.Value) for x in contact.ItemProperties)
else …Run Code Online (Sandbox Code Playgroud)