Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter out values from python mysql query

I am using mysql.connector in python to get a list of values from a database.

can you please help extract each value from the list separately

my code is as below

cnx = mysql.connector.connect(host=mysql_localhost, user=user, password=password, database=database)
cursor = cnx.cursor()
cursor.execute("select  * from settings" )
results = cursor.fetchall()
print(results)

and the result I am getting is a list as follow

[(0, 3232235535L, 0, 12, 12.1, 22.5, 29.0)]

What I would like to do then is get each value (being integer or float) separately from the list above

like image 818
Ossama Avatar asked Feb 05 '26 08:02

Ossama


1 Answers

Use a for loop:

for each in results[0]:
    ...

Or if you do want assign them to variables:

a, b, c, d, e, f, g = results[0]
like image 68
zhangyangyu Avatar answered Feb 06 '26 21:02

zhangyangyu