Reputation: 77
so I'm using mysql to grab data from a database and feeding it into a python function. I import mysqldb, connect to the database and run a query like this:
conn.query('SELECT info FROM bag')
x = conn.store_result()
for row in x.fetch_row(100):
print row
but my problem is that my data comes out like this (1.234234,)(1.12342,)(3.123412,)
when I really want it to come out like this: 1.23424, 1.1341234, 5.1342314 (i.e. without parenthesis). I need it this way to feed it into a python function. Does anyone know how I can grab data from the database in a way that doesn't have parenthesis?
Upvotes: 2
Views: 114
Reputation: 1386
You could also simply use this as your for loop:
for (info, ) in x.fetch_row(100):
print info
Upvotes: 0
Reputation: 82924
Rows are returned as tuples, even if there is only one column in the query. You can access the first and only item as row[0]
The first time around in the for
loop, row
does indeed refer to the first row. The second time around, it refers to the second row, and so on.
By the way, you say that you are using mySQLdb
, but the methods that you are using are from the underlying _mysql
library (low level, scarcely portable) ... why??
Upvotes: 2