[python] Figured out how to go from email.Message.Message to string

D

David Stockwell

It took a little bit of digging but I finally figured it out by looking in
my /usr/local/lib/py* directory's python modules.

Turns out in the Message.py module there is a __str__ method you can call to
convert to a string. And when i read more I found out its doing a fancy
flatten. I've seen references to flatten around so this will help reinforce
in my mind what it means for a flat tened or flat python object.




David
-------
Tracfone: http://cellphone.duneram.com/index.html
Cam: http://www.duneram.com/cam/index.html
Tax: http://www.duneram.com/index.html

_________________________________________________________________
Looking to buy a house? Get informed with the Home Buying Guide from MSN
House & Home. http://coldwellbanker.msn.com/
 
D

David Bolen

David Stockwell said:
Turns out in the Message.py module there is a __str__ method you can
call to convert to a string. And when i read more I found out its
doing a fancy flatten. I've seen references to flatten around so this
will help reinforce in my mind what it means for a flat tened or flat
python object.

Note that any object's __str__ method provides a default way to create
a "nicely" printable string representation of that object, but you
won't normally call that method directly. Instead, it will be called
indirectly if you use the object in a print statement, or as an
argument to the %s string formatting operator, or if you use the str()
built-in method on that object.

Also note that the __str__ implementation for Message includes a Unix
formatted "From" line (the format used in some Unix mailbox files).
If you just want the plain message, you may want to use the
as_string() method on the Message object instead which has a parameter
to conditionalize the from line (off by default).

-- David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top