Gabriel Genellina gagsl-py2 at
Sat Jul 14 14:14:51 CEST 2007

En Sat, 14 Jul 2007 06:26:43 -0300, Tzury <Afro.Systems at>  

>> What do you actually think
>> ...     for m in msg:
>> ...             print m
>> should do? Why do you believe that what you think it should do would be
>> a natural choice?
> I needed to know how to extract particular parts of a message, such as
> the message 'body', 'subject', 'author', etc.
> I couldn't find it in the documentation this kind of information until
> I ran the inspect.getmembers(msg)

Well, you took the hard way... the easy way would be to read the  

> and found out that the message body
> stored in _payload. that is msg._payload is the content of the
> message.

You should perceive the initial _ in _payload as a yellow light - a  
warning. It's an implementation detail and one should avoid messing with  
it - best to stick to the documented API, get_payload() in this case.

> Regarding the *bug* thing it is very simple. If you iterate an int you
> get an exception <TypeError: 'int' object is not iterable>, clear
> enough. Yet here I got the following exception <AttributeError: 'int'
> object has no attribute 'lower'> which suggest an attempt to iterate
> ---. I do think that a message should support iteration for the very
> fact that each can contain a different type and amount of headers, and
> iteration in this case will make application's code clean and unified.

I don't see what you mean. You can always enumerate the message headers  
using msg.keys(), along with has_key(), items(), etc. And what you want to  
unify the code with?

Even if Message becomes iterable, I still don't see why should iteration  
over its *headers* be the preferred meaning. For a multipart/* MIME  
message, iterating over the parts looks much more interesting.

Gabriel Genellina

More information about the Python-list mailing list