payload of an email in string format, python
Question: I got payload as a string instance using `get_payload()` method. But I want my
payload in a way where I could access it word by word I tried several things
like `as_string() method, flatten() method, get_charset() method` , but every
time there is some problem.

I got my payload using the following code

    
    
    import email
    from email import *
    f=open('mail.txt','r')
    obj=email.parser.Parser()
    fp=obj.parse(f)
    payload=fp.get_payload()
    


Answer: Just tested your snippet with a couple of my own raw emails. Works fine...

get_payload() returns either a list or string, so you need to check that first

    
    
    if isinstance(payload, list):
        for m in payload:
            print str(m).split()
    
    else:
        print str(m).split()
    

**Edit**

Per our discussion, your issue was that you were not checking is_multipart()
on the fp object, which actually is a message instance. If fp.is_multipart()
== True, then get_payload() will return a list of message instances. In your
case, based on your example mail message, it was NOT multipart, and fp was
actually the object you were interesting in.

