Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2699

Re: TypeError: iterable argument required

From Νικόλαος Κούρας <nikos.kouras@gmail.com>
Newsgroups comp.lang.python
Subject Re: TypeError: iterable argument required
Date 2011-04-06 03:06 -0700
Organization http://groups.google.com
Message-ID <edadfb9d-c411-482e-85ad-19dbf54b3190@cu4g2000vbb.googlegroups.com> (permalink)
References <3721a54c-6814-4f11-9bde-eee60c45e88d@glegroupsg2000goo.googlegroups.com>

Show all headers | View raw


On 5 Απρ, 05:49, "eryksun ()" <eryk...@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:

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

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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: TypeError: iterable argument required "eryksun ()" <eryksun@gmail.com> - 2011-04-04 19:49 -0700
  Re: TypeError: iterable argument required Νικόλαος Κούρας <nikos.kouras@gmail.com> - 2011-04-06 03:06 -0700
    Re: TypeError: iterable argument required Terry Reedy <tjreedy@udel.edu> - 2011-04-06 13:06 -0400

csiph-web