python - TypeError: 'long' object has no attribute '__getitem__' for MySQL -
i trying retrieve data mysql table.
my code
def getdata(self, id): #load data mysql query = 'select * goals id = "%s"'% (id) try : cursor.execute(query) data = cursor.fetchone() conn.commit() except exception e: raise e data = false if data not false: row in data: self.id = row[0] self.description = row[1] self.imageid = row[2] self.imagelink = row[3] self.location = row[4] self.status = row[5] self.publishid = row[6] self.goardid = row[7] self.likesid = row[8] self.createddate = row[9] self.createdtime = row[10] self.hide = row[11] x = newthink() print x.create_new() print x.goalid, x.subscriptionid, x.likesid, x.goardid see = x.adddata('just second', 'nairobi', 89900845,'http://image.com/789900845') print see see = x.postdata() print see see = x.getdata(x.goalid) print see print "now here formatted data../n" print '........' print x.description, x.location, x.imageid, x.imagelink
the error : typeerror: 'long' object has no attribute 'getitem'
this error keep getting. returns tuple guess im not sure
you should indicate error occurs. can make guess:
data = cursor.fetchone() .... row in data: self.id = row[0] ...
data
tuple, values 1 row
. for row in data
iterates on tuple, row
individual fields. error indicates 1 of other row
number, long
.
if used data = cursor.fetchall()
, there multiple rows
data, , rest work.
alternatively stick fetchone
, skip for row in data
loop. use data[0]
, etc.
in sum, make sure understand structure of data
. might not list (or other iterable) of tuples code assumes.
Comments
Post a Comment