TypeError: iterable argument required

Peter Otten __peter__ at web.de
Mon Apr 4 16:38:42 CEST 2011


Νικόλαος Κούρας wrote:

>> if "@" in mail and comment not in INVALID_COMMENTS:

> In my original question can you explain to me what the meaning of the
> following error is?
> 
> ********************************************
> mail = None, comment = None
> TypeError: iterable argument required
> args = ('iterable argument required',)
> *********************************************

That's not the standard format for a traceback in Python and you don't 
provide enough context like: 

- your python version
- the framework that produces the non-standard traceback
- a significant portion of your code

That makes it harder than necessary to find out what's going on.

Python 2.4.6 (#2, Jan 21 2010, 23:45:25)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "@" in None
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: iterable argument required

So "mail = None" means exactly that, you somehow assigned None to the mail 
variable.

Note that newer Python versions give a slightly improved error message:

$ python2.5 -c '"@" in None'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: argument of type 'NoneType' is not iterable

Background: the 'in' operator tries hard to produce a meaningful result 
before it gives up:

>>> class A:
...     def __getattr__(self, name):
...             print name
...             raise AttributeError
...
>>> 42 in A()
__contains__
__iter__
__getitem__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument of type 'instance' is not iterable




More information about the Python-list mailing list