在windows平台上安装sqlite3,并且python3.x调用

在网址  https://www.sqlite.org/download.html 下载

解压到windows下某个目录,如D:\数据\sqlite-tools-win32-x86-3280000

在path环境变量中加入此目录,可以在【系统属性】-【环境变量】中添加。也可以临时如下命令行cmd添加

set path=%path%;D:\数据\sqlite-tools-win32-x86-3280000

安装sqlite3的python库, 如"C:\Program Files\Python37\python.exe" -m pip install pysqlite3

之后就可以编写sqlite3的python代码,调用它了,如

from faker import Faker
import sqlite3

fake= Faker("zh_cn")
conn= sqlite3.connect("test.db");
c=conn.cursor()
c.execute("create table user( id varchar(20) \
       primary key, name varchar(20))")
for i in range(10):
     c.execute("insert into user(id, name) \
        values ('{}', '{}')".format(i,fake.name()))
c.execute("select * from user")
result=c.fetchall()
print(result)       

运行结果如下

发布了29 篇原创文章 · 获赞 5 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/foolpanda1168/article/details/90340351