So I am trying to run a simple query in python using sqlite to try it out . I get the result of the query right, but I get an extra "u" at the beginning of each text field and I am not sure why. Here is the code:
import sqlite3
db = sqlite3.connect(':memory:')
c = db.cursor()
c.execute("create table Students (ID INTEGER Primary key AUTOINCREMENT, FN text, LN text);")
c.execute("INSERT into Students (FN,LN) Values ('FirstName','LastName');")
c.execute("Select * from Students")
for i in c:
print(i)
and here is the result I get:
(1, u'FirstName', u'LastName')
Process finished with exit code 0
any clue why this happens ? Thanks
In Python source code, Unicode literals are written as strings prefixed with the u
or U
character.
If you don't want that your word became unicode you can encode with unicode-escape
:
>>> s.encode('unicode-escape')
'FirstName'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.