TypeError: iterable argument required

Νικόλαος Κούρας nikos.kouras at gmail.com
Wed Apr 6 06:06:06 EDT 2011

On 5 Απρ, 05:49, "eryksun ()" <eryk... at gmail.com> wrote:
> On Monday, April 4, 2011 9:40:33 AM UTC-4, Νικόλαος Κούρας wrote:
> In one of your messages you wrote the following:
> > cursor.execute( '''INSERT INTO users(mail, comment) VALUES(%s,
> > %s)''', (mail, comment) )
> > except MySQLdb.Error:
> > print ( "Error %d: %s" % (e.args[0], e.args[1]) )
> Is this a typo in your message or the actual code? If 'e' is unassigned you should be getting a NameError. The standard Python2 syntax (before version 2.6) is the following:
>     except MySQLdb.Error, e:
>         print("Error %d: %s" % (e.args[0], e.args[1]))
> You also wrote:
> > mail = None, comment = None
> This should cause a SyntaxError because it's trying to assign None = None. That's assuming it's on line 167, after the cursor.execute(...) on line 166.
> > Whats was the problem as i have written it?
> > Your solution is the same as mine except the fact that you assign
> > values and statements into variables.
> I was just rewriting it to make sure I was parsing it right.
> > I tried it but iam getting an Internal Server Error.
> > Also i noticed that if i append a query string in the end of a url
> > with the varibble mail attached like
> >http://superhost.gr/hosting.html?mail=test
> > then page hosting.html does load without any problem.
> > If i remove the query string from the ned of the URL then i'am getting
> > the error message i posted.
> > So its not that the if condition is wrong but something happens with
> > the form variable 'mail' .....
> Insert a test to print out the type and value of 'mail' for various inputs.
> Regarding the message itself, on Python 2.7.1, I get the following TypeError message if I try iterate None:
>     TypeError: argument of type 'NoneType' is not iterable
> Python 2.5.2 on "http://shell.appspot.com" yields the same error. Version 2.5 improved the error messages to include the type of the object (see issue 1507676). The message "iterable argument required" looks like an older version of CPython.

Thank you you were right.

The trouble was in `if "@" in mail` .
You can only test somthing `in` something else if the second thing is
iterable and None isnt.

So i made the code look like this:

if ( mail is not None and '@' in mail ) and comment not in ("Ρωτήστε
με σχετικά...", "", None):

Now it works like i wanted but i want to ask you if i wrote it
correctly, especially when i check against `""` and None

And please explain to me the difference betweeen an empty string `""`
and None.
An empty string is still a string with zero characters within?

> Yes, I made a mistake. It should have been `cursor.execute(SQL_COMMENT_FORM, (mail, comment))`, using a >comma instead of a '%' to have it generate SQL string literals from the tuple.

What do you mean by  "to have it generate SQL string literals from the
tuple." Please explain

More information about the Python-list mailing list