我正在向电子邮件发送一个字符串,我希望每行一个句子,如下所示:
"Loaded LLARY_AR with 0 features
Loaded LLARY_LN with 44 features
Loaded LLARY_PT with 23 features"
但是当我在字符串连接中添加一个换行符时,我得到两个换行符而不是一个,如下所示:
"Loaded LLARY_AR with 0 features
Loaded LLARY_LN with 44 features
Loaded LLARY_PT with 23 features"
如果我不包含换行符,我会得到:
"Loaded LLARY_AR with 0 features Loaded LLARY_LN with 44 features Loaded LLARY_PT with 23 features"
这是代码:
msgemail = ""
for fcl in trnlist:
try:
tofc = param["tsde"]+"\\"+param["trema"]+fcl
fromfc = param["msde"]+"\\"+param["mchema"]+fcl
arcpy.DeleteFeatures_management(tofc)
arcpy.Append_management(fromfc, tofc)
msgemail +="\nLoaded "+fcl+" with "+str(arcpy.GetCount_management(fromfc))+" features"
del fcl, tofc, fromfc
except:
msgemail +="\nUnsuccessful!! "+fcl
emailto = ["email@to","email@to"]
server = smtplib.SMTP('server.here')
header = "Results:\n"
subject = "Data"
mailmessage = header+msgemail+"\n\nCheck log for details"
message = 'Subject: %s\n\n%s' %(subject, mailmessage)
for e in emailto:
try:
server.sendmail("email@from",e, message)
except:
arcpy.AddMessage(e+" was not sent an email.")
server.quit()
我不明白为什么换行符会以这种方式行事……而新手……显然在这里遗漏了一些东西。
我发现这可以生成格式良好的电子邮件(但不包括来自 ..GetCount..process 的必要信息):
msgemail +="\nLoaded"+fcl
虽然这些不会产生格式良好的电子邮件:
msgemail +="\nLoaded "+fcl+" with "+str(arcpy.GetCount_management(fromfc))+" features"
msgemail +="\nLoaded "+fromcnt
msgemail +="\nLoaded "+fromcnt+" testing for string at end"