[python] Figured out how to go from email.Message.Message to string
db3l at fitlinxx.com
Thu Jun 17 16:52:37 EDT 2004
"David Stockwell" <winexpert at hotmail.com> writes:
> 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).
More information about the Python-list