我是靠谱客的博主 清脆太阳,这篇文章主要介绍python数据库输出结果存到列表中_SQL数据库查询返回具有列表中所有值的记录(Python)...,现在分享给大家,希望可以做个参考。

如果我理解正确,“like”子句符合您的要求,但您不知道如何将列表转换为“like”子句。在

所以代码如下:import sqlite3

with sqlite3.connect("animeData.db") as db: #anime database

c = db.cursor()

#self.genreResults is the list containing the genres i want to query

user_input = self.genreResults # for example: ['Action','Drama']

convert_to_like_conditions = ' and '.join(list(map(lambda item : "genre like '%{0}%'".format(item), user_input)))

print(convert_to_like_conditions) #Output: genre like '%Action%' and genre like '%Drama%'

c.execute("select * from t where %s" % convert_to_like_conditions )

results = c.fetchall()

print(results)

db.commit()

最后

以上就是清脆太阳最近收集整理的关于python数据库输出结果存到列表中_SQL数据库查询返回具有列表中所有值的记录(Python)...的全部内容,更多相关python数据库输出结果存到列表中_SQL数据库查询返回具有列表中所有值内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(141)

评论列表共有 0 条评论

立即
投稿
返回
顶部