I have a function that runs through a list and then loads a dictionary. It prints out fine within the function but the return dict is empty?
95 def getAttachmentDict(messageIds):
96 messageTable = defaultdict(list)
97 for id in messageIds:
98 uri = "/message/" + id
99 res = getMessages(uri)
100 doc = xml.dom.minidom.parse(res)
101 idUrl = doc.getElementsByTagName("url")
102 alist = []
103 for i in idUrl:
104 urlData = i.childNodes[0].nodeValue
105 alist.append(urlData)
106 messageTable[id] = alist
107 print "\n"
108 for key, value in messageTable.items():
109 print "Message ID: " + key
110 print "\n".join(value)
111 return messageTable
169 getAttachmentDict(messageIds)
170 pdb.set_trace()
171 print messageTable
Message ID: MyUHRnzm7AXkFmiKocUjzn config-safety-report.html Message ID: RqfljNnyz63bBpGLtL4B2D individual-report.csv
/Work/ftpTool/acquire.py(171)main() -> print messageTable (Pdb) n {}
You're not doing anything with the return value. This is just printing some other variable you've called messageTable
169 getAttachmentDict(messageIds)
170 pdb.set_trace()
171 print messageTable
try this instead
169 messageTable = getAttachmentDict(messageIds)
170 pdb.set_trace()
171 print messageTable
When you call getAttachmentDict()
, you need to assign the result to a name (which could be messageTable
, or any other name you want to use). For example:
169 messageTable = getAttachmentDict(messageIds)
170 pdb.set_trace()
171 print messageTable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.