Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 数据库SQlite3 python3的输入速度慢_Python 3.x_Sqlite - Fatal编程技术网

Python 3.x 数据库SQlite3 python3的输入速度慢

Python 3.x 数据库SQlite3 python3的输入速度慢,python-3.x,sqlite,Python 3.x,Sqlite,我正在尝试使用python在本地SQLite3DB上保存用户名。我是新来的。我的表有10000行,只有一列用户名,但插入所有10k值需要半个多小时。我做错了什么?有什么线索吗?我的代码 def create_table(channel_username): c.execute("CREATE TABLE IF NOT EXISTS {}(user_name UNIQUE)".format(channel_username)) conn.commit() def insert

我正在尝试使用python在本地SQLite3DB上保存用户名。我是新来的。我的表有10000行,只有一列用户名,但插入所有10k值需要半个多小时。我做错了什么?有什么线索吗?我的代码

 def create_table(channel_username):
    c.execute("CREATE TABLE IF NOT EXISTS {}(user_name UNIQUE)".format(channel_username))
    conn.commit()


def insert_username(channel_username,user_name):
    c.execute("INSERT OR IGNORE INTO {} VALUES(?)".format(channel_username),[user_name])
    conn.commit()


create_table(channel_username)

x= client.get_participants(channel_username, aggressive=True)

z=[]
for user in x:

    z.append(user.username)

fl = [i for i in z if i is not None]

fl.sort()

for user_name in fl:

    insert_username(channel_username,user_name)

print("DBfached successful")

插入不慢;所有的
commit()
调用都很慢

删除它们,并仅在实际完成时执行
commit()

阅读会给您一些提示。python-sqlite绑定没有C-API的特性或功能,但是仍然有一些东西可以从中获得。从事务开始,同时阅读
executemany()
方法。