2013-07-19 57 views
3

我使用mysql.connector库按照下面的代码过滤蟒蛇的MySQL结果

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() 

结果如下

u'admin' 

运行从Python中的MySQL查询我注意到,在存储的值数据库作为varchar显示与u'' 我怎样才能得到没有u'的值所以所需的输出是

admin 

回答

0

在变量前面的u意味着它是一个unicode string。这真的是一个问题吗?如果您确实需要将其转换为常规字符串,则可以使用str(user)

1

u表示这是一个unicode字符串。您应该阅读Unicode HOWTO以获得更好的理解。