简体   繁体   English

Python-遍历列表

[英]Python - iterate through a list

I'm trying to automate email reporting using python. 我正在尝试使用python自动执行电子邮件报告。 My problem is that i cant pull the subject from the data that my email client outputs. 我的问题是我无法从电子邮件客户端输出的数据中提取subject

Abbreviated dataset: 缩写数据集:

[(messageObject){
   id = "0bd503eb00000000000000000000000d0f67"
   name = "11.26.17 AM [TXT-CAT]{Shoppers:2}"
   status = "active"
   messageFolderId = "0bd503ef0000000000000000000000007296"
   content[] = 
      (messageContentObject){
         type = "html"
         subject = "Early Cyber Monday – 60% Off Sitewide "
         }
         }
         ]

I can pull the other fields like this: 我可以像这样拉其他字段:

messageId = []
messageName = []
subject = []

for info in messages:
    messageId.append(str(info['id']))
    messageName.append(str(info['name']))
    subject.append(str(info[content['subject']]))

data = pd.DataFrame({
    'id': messageId,
    'name': messageName,
    'subject': subject
}) 
data.head()

I've been trying to iterate though content[] using a for loop, but i can't get it to work. 我一直在尝试使用for循环遍历content[] ,但是我无法使其正常工作。 Let me know if you have any suggestions. 如果您有任何建议,请告诉我。

@FamousJameous gave the correct answer: @FamousJameous给出了正确答案:

That format is called SOAP. 该格式称为SOAP。 My guess for the syntax would be info['content']['subject'] or maybe info['content'][0]['subject'] 我对语法的猜测是info['content']['subject']info['content'][0]['subject']

info['content'][0]['subject'] worked with my data. info['content'][0]['subject']处理了我的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM