How to tackle this python-mysql problem

import mysql.connector
mydb = mysql.connector.connect
(

host=“localhost”,
user=“root”,
passwd=“1234567890”,
database=“Mypal”

)

print(mydb)

name = “abhi”

mycursor = mydb.cursor()

sql = “select user_total_assets from users_info where user_name = %s”

val = (name,)

mycursor.execute(sql,val)

my_result = mycursor.fetchall()

print(my_result)

for i in my_result:

print(i)

i’m stuck on the output of i as an tuple which is (‘100’,) but I need output as 100 which would be an integer, so how to convert this tuple into an integer?

If that’s all you’re changing have you come across int()?

Yes,I’ve tried to use int() but is says tuples are not converted to int

Thanks


You can’t convert a tuple to an int, but you can convert the string inside the tuple into an int:

for i in my_result:
    for j in i:
        print(int(j))

Of course you probably don’t want to just print the int value, but this should show you how to access the string inside the tuple.

Happy coding!

Thanks el_cocodrilo, now its working, god bless you