Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter python mysql result

Tags:

python

mysql

I am running a mysql query from python using mysql.connector library as per code 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()
ID, server, port, user, password, temp_min ,temp_max = results[0]
print(user)
cursor.close()
cnx.close()

the result is as follow

u'admin'

I noticed that values stored in the database as varchar display with u'' how can I get the value without the u'' so the desired output is

admin
like image 854
Ossama Avatar asked Mar 24 '26 02:03

Ossama


1 Answers

u means that this is a unicode string. You should read Unicode HOWTO for better understanding.

like image 146
alecxe Avatar answered Mar 25 '26 19:03

alecxe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!