How to add a current string into an already existing list
denismfmcmahon at gmail.com
Tue Nov 5 18:48:24 CET 2013
On Tue, 05 Nov 2013 11:34:53 +0200, Nick the Gr33k wrote:
>>> data = cur.fetchall
>>> for row in data:
> I see, but because of the traceback not being to express it more easily
> i was under the impression that data wasn't what i expected it to be.
data wasn't what you expected it to be.
The problem was that you didn't understand that the reason data wasn't
what you expected it to be was that you had assigned data to be the
fetchall method of the object cur, when what you wanted to do was assign
data to be the results of executing the method fetchall on the object cur.
Both of these are legal assignments:
data = cur.fetchall
data = cur.fetchall()
However the following is only valid if data is iterable:
for row in data:
So when it reaches the the line:
for row in data:
and discovers that data is not an iterable type, it gives an error
message. If you can't decipher the error message to get back to the fact
that in this case data isn't a y that you can use "for x in y:" to
iterate over, and then debug intelligently to determine how any why that
error message occurred, then as has been suggested many times in the
past, you should stop trying to write code.
Seriously, how many other people do you see repeatedly posting "I don't
understand the error, help" messages here that have been caused by such
simple coding mistakes?
Most of us can decipher these error messages ourselves and would be
embarrassed to post asking for help.
Denis McMahon, denismfmcmahon at gmail.com
More information about the Python-list