我遇到过这样一种情况:销售经理会自动回复一封电子邮件,其中包含主要和次要潜在客户的交付周期。他们的回答将包括它是哪种类型的铅和铅的时间指示。例如:
Primary_Lead 10
Secondary_Lead 20
我写了一个脚本来浏览电子邮件(基于某个主题),并在回复中找到提前期。我想把这些加到交货期表字典里。我认为除了我的最后两行将值附加到Sales Manager
和Lead Time
之外,一切都正常。我做错什么了?我知道整个电子邮件增加了额外的复杂程度,我不需要帮助,但我想提供实际的代码。你知道吗
import win32com.client
import re
olFolderInbox = 6
olMailItem = 0
outlook = win32com.client.Dispatch("Outlook.Application")
mapi = outlook.GetNamespace('MAPI')
inbox = mapi.GetDefaultFolder(olFolderInbox)
My_Folder = inbox.Folders("Leads")
Lead_Time = {
'Primary_Leads': {'Sales Manager' : [],'Lead Time' : []},
'Secondary_Leads': {'Sales Manager' : [],'Lead Time' : []}
}
for i in range (My_Folder.Items.Count): #loops through all emails in Leads Folder
message = My_Folder.Items[i] #sets the message
if "RE: Lead Time Report" in message.Subject: #checks for a certain subject
for tbl in Lead_Time:
if tbl.upper() in message.Body.upper():
tbl['Sales Manager'].append map(int,re.findall(tbl +"* (\d+)",message.Body,re.I))
tbl['Lead Time'].append message.sender
当您真的想要附加到值时,您正在迭代
Lead_Time
的键。你知道吗您可以在自己的代码中看到这种混淆:
在第二行中,您将
tbl
视为字符串。在第三行,您将tbl
视为字典中与其关联的数组值。你知道吗您可以按以下方式更改代码:
或者您可以在迭代时同时请求键和值:
您可以通过以下更简单的示例看到默认dict迭代器的输出:
打印1和3。你知道吗
相关问题 更多 >
编程相关推荐