我是 Python 新手,遇到了一个我无法克服的错误。
如果主题与给定字符串匹配,则编写代码以浏览我的前景并提取附件(excel)。这是代码:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
print "Inbox name is:", inbox.Name
messages = inbox.Items
message = messages.GetFirst ()
while message:
if message.Subject.startswith('EOD Report'):
attachments = message.Attachments
if attachments.Count>=1:
attachment = attachments.Item(1)
filename = 'c:\Users\xx\Python\%s'%attachment
print filename
attachment.WriteToFile(filename)
message = messages.GetNext()
如果我摆脱'attachment.WriteToFile(filename)',它运行得很好。但是,该特定语句会产生错误:
Traceback (most recent call last):
File "C:\Users\xx\.spyder2\.temp.py", line 31, in <module>
attachment.WriteToFile(filename)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 522, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: Item.WriteToFile
有谁知道出了什么问题?谢谢