Roman Suzi <rnd@onego.ru> wrote:[color=blue]
>
>I was playing with email package and discovrered this strange kind of
>behaviour:
>[color=green][color=darkred]
>>>> import email.Message
>>>> m = email.Message.Message()
>>>> m['a'] = '123'
>>>> print m[/color]
>>From nobody Mon Feb 21 00:12:27 2005[/color]
>a: 123
>[color=green][color=darkred]
>>>> for i in m: print i[/color][/color]
>...
>Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/lib/python2.3/email/Message.py", line 304, in __getitem__
> return self.get(name)
> File "/usr/local/lib/python2.3/email/Message.py", line 370, in get
> name = name.lower()
>AttributeError: 'int' object has no attribute 'lower'[/color]
Intuitively, what did you expect this to do? I don't see why a single
message should be iterable.
[color=blue]
>I think that if any object (from standard library at least) doesn't support
>iteration, it should clearly state so.[/color]
That's going a bit far. Iteration is a relatively new addition to Python.
Those classes that DO support iteration generally say so. If it isn't
mentioned, you probaby shouldn't assume it.
[color=blue]
>Can this behaviour of email be considered a bug?[/color]
Not in my opinion, no.
[color=blue]
>Is there a good case to iterate over something useful in a message?[/color]
Well, if you don't have an answer to that question, then why would you
expect it to support iteration?
[color=blue]
>P.S. rfc822 has the same behaviour, at least on Python 2.3[/color]
Again, I'm not sure what, intuitively, it would mean to iterate over an
rfc822 object.
--
- Tim Roberts,
timr@probo.com
Providenza & Boekelheide, Inc.