简体   繁体   中英

find all items in list object

I would like to interrogate all new emails (one by one) and find the contents of them so that I can use the contents for another application.

My first step was interpreting the return values from a search done via the search attr of an IMAP4 object. I'm trying to figure out what data is in a list that I have returned to me.
How can I examine the object tree via print? Or, better yet, how can I get the contents of the email in a string?

For ex., I am returned the following via print: unseen email content: ['3 4'] from a variable named "response". If I run print response.__class__.__name__ , I get "list" returned.

I know that there is other data in "3", and "4", I just don't know what.

update: Specifically, this is the return of a call to an IMAP4obj.search(None, '(UNSEEN)')

You may try importing pdb and doing a pdb.pprint.pprint(response)

If it's a program running on your own machine, you can also do a pdb.set_trace() and play with response.

The ipdb module has nicer versions, but it's not usually installed by default.

from the python docs ( here ) this example:

# M is a connected IMAP4 instance...
typ, msgnums = M.search(None, 'FROM', '"LDJ"')

it seems a tuple is returned, you can try,

print(type(typ))
print(dir(typ))
print(type(msgnums))
print(dir(msgnums))

try reading the docs, see if it can help clarify your doubts or even make your question clearer.

Sounds like a debugger might help. If you are using an IDE with a debugger set a break point and introspect the objects.

If you do not use an IDE yet, try Eclipse in combination with PyDev

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.

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