小编fra*_*aga的帖子

win32com.client.Dispatch 有效,但 win32com.client.gencache.EnsureDispatch 无效

我正在学习 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)

python outlook pywin32 dispatch win32com

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

dispatch ×1

outlook ×1

python ×1

pywin32 ×1

win32com ×1