use*_*434 2 python sqlite python-2.7
我试图在python 2.7(Windows)中运行以下内容,它给了我一个错误:
ProgrammingError:除非使用可解释8位字节字符串的text_factory(如text_factory = str),否则不得使用8位字节串.强烈建议您只需将应用程序切换为Unicode字符串.
#!/usr/bin/python
# -*- encoding: utf-8-*-
import sqlite3;
db = sqlite3.connect('db.sqlite3')
cursor = db.cursor()
cursor.execute('INSERT INTO X(id,a,b) VALUES(?,?,?)', (999998,"?---?---?---ó---??","ssf"))
cursor.execute('SELECT * FROM X where id = 999998')
for row in cursor:
print row
db.commit()
db.close()
Run Code Online (Sandbox Code Playgroud)
如何将这些字符串("ąźć"=波兰标志)插入我的sqlite数据库?
您可以按照他们的建议:"只需将应用程序切换为Unicode字符串即可."
cursor.execute(
'INSERT INTO X(id,a,b) VALUES(?,?,?)',
(999998,u"?---?---?---ó---??","ssf"))
Run Code Online (Sandbox Code Playgroud)
请注意u
字符串文字之前.这使它成为unicode文字.
归档时间: |
|
查看次数: |
8057 次 |
最近记录: |