在SQLite-Python中实现返回、查询中文字段的方法
作者:Joy_917 时间:2022-05-31 00:17:32
博主在这个问题上卡了挺久的,贴出来解决方法帮助需要的朋友,直接上代码(测试环境:win10+Python2.7):
# coding=utf-8
import sqlite3
with sqlite3.connect(":memory:") as conn:
try:
init_sql = " create table test (id integer primary key ,name text(200) not null);" \
" insert into test (name) values ('小居居');" \
" insert into test (name) values ('大居居');"
conn.executescript(init_sql)
except Exception as e:
conn.rollback()
raise e
else:
conn.commit()
conn.text_factory = str # 此处是关键,sqlite默认文本存取是Unicode
try:
for row in conn.execute(" select * from test where name = ?",("大居居",)):
print row[1],type(row[1])
except Exception as e:
raise e
结果:
大居居 <type 'str'>
来源:https://blog.csdn.net/qq_35221523/article/details/79398643
标签:SQLite,Python,查询,中文字段
0
投稿
猜你喜欢
Python中的基本数据类型介绍
2023-07-21 22:26:26
python调用摄像头的示例代码
2021-10-11 02:18:09
找Python安装目录,设置环境路径以及在命令行运行python脚本实例
2022-06-01 23:28:56
Python matplotlib实用绘图技巧汇总
2023-10-05 01:12:39
Django 多对多字段的更新和插入数据实例
2022-09-11 01:17:04
Python将字典转换为XML的方法
2023-08-04 16:13:22
Appium+Python实现简单的自动化登录测试的实现
2021-09-13 05:49:14
python实现批量图片格式转换
2021-07-15 16:07:42
python基本数据类型练习题
2022-07-21 14:26:26
pytorch交叉熵损失函数的weight参数的使用
2021-02-27 15:52:31
python实现Nao机器人的单目测距
2021-04-09 16:37:10
Python基础之getpass模块详细介绍
2021-03-06 13:47:13
对python3中的RE(正则表达式)-详细总结
2022-12-28 23:33:41
Python中常用的os操作汇总
2022-12-13 08:30:16
安装PyTorch的详细过程记录
2023-05-12 07:50:12
教程:纯CSS作的小灯笼效果
2008-08-26 17:22:00
[JS]点出统计器
2013-07-22 03:23:24
python判断变量是否为列表的方法
2023-05-06 16:22:22
pandas的qcut()方法详解
2022-07-23 03:36:21
PyTorch之nn.ReLU与F.ReLU的区别介绍
2021-01-19 04:47:24