我正在尝试在 python 上使用 sqlite:
from pysqlite2 import dbapi2 as sqlite
con = sqlite.connect('/home/argon/super.db')
cur = con.cursor()
cur.execute('select * from notes')
for i in cur.fetchall():
print i[2]
我有时会得到这样的东西(我来自俄罗斯):
Ответ etc...
如果我将此字符串传递给此函数(它在其他项目中对我有帮助):
def unescape(text):
def fixup(m):
text = m.group(0)
if text[:2] == "&#":
# character reference
try:
if text[:3] == "&#x":
return unichr(int(text[3:-1], 16))
else:
return unichr(int(text[2:-1]))
except ValueError:
pass
else:
# named entity
try:
text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
except KeyError:
pass
return text # leave as is
return re.sub("&#?\w+;", fixup, text)
我得到更奇怪的结果:
ÐÑвеÑиÑÑ Ñ ÑиÑиÑованием etc
我应该怎么做才能获得正常的西里尔符号?