Roman Suzi <[EMAIL PROTECTED]> wrote: > >I was playing with email package and discovrered this strange kind of >behaviour: > >>>> import email.Message >>>> m = email.Message.Message() >>>> m['a'] = '123' >>>> print m >>From nobody Mon Feb 21 00:12:27 2005 >a: 123 > >>>> for i in m: print i >... >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'
Intuitively, what did you expect this to do? I don't see why a single message should be iterable. >I think that if any object (from standard library at least) doesn't support >iteration, it should clearly state so. 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. >Can this behaviour of email be considered a bug? Not in my opinion, no. >Is there a good case to iterate over something useful in a message? Well, if you don't have an answer to that question, then why would you expect it to support iteration? >P.S. rfc822 has the same behaviour, at least on Python 2.3 Again, I'm not sure what, intuitively, it would mean to iterate over an rfc822 object. -- - Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list