使用python win32com包读取电子邮件后,Outlook变得缓慢

问题描述 投票:0回答:1

当我使用win32com访问Outlook 2013时,我运行代码后的前景非常慢。下面是我的代码:

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
                                    # the inbox. You can change that number to reference
                                    # any other folder
emails = outlook.GetDefaultFolder(6).Folders['xyz'].Folders['abc'].Items

有时我得到com_error:(-2146959355,'服务器执行失败',无,无)运行代码如果事先打开outlook。我将不得不重新启动outlook并重置我的python env以恢复正常。在阅读电子邮件后,我需要设置outlook中的任何设置或任何特殊的python操作吗?

最诚挚的问候,杰里米

python outlook win32com
1个回答
0
投票

你有没有退出win32com应用程序?如果它仍然与计算机上的其他程序一起运行,它会吸收内存/其他资源并使原始Outlook变慢,这是我的猜测。

我运行像Word这样的Word应用程序

def win32_word_dispatch():#懒惰导入win32com - 不要在没有调用它们时加载Windows / MS Office库。导入win32com.client为win32 word = win32.Dispatch(“Word.Application”)word.Visible = 0返回单词

并尝试将其关闭为:

def close_ms_word(app):app.Quit()#ISSUE:还必须通过在#http://bytes.com/topic/python/answers/23946-closing-excel-application中调用app.Quit()#来退出某处

© www.soinside.com 2019 - 2024. All rights reserved.