如何使用variab中存储的值创建或打开数据库

2024-04-24 09:51:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用sqlite在数据库中存储一些值,但是这些值来自不同的源,所以我必须将它们放在不同的数据库中,所以我尝试了以下方法:

 source_name = "hello"
 ext = ".db"
 path = "d:/"
 fullpath = path + source_name + ext
 db = sqlite3.connect("%s") % (fullpath)

但它不起作用,任何解决方案或想法

报告的错误是:

%s在引号内:

 TypeError: unsupported operand type(s) for %: 'sqlite3.Connection' and 'str'

%s不带引号:

 SyntaxError: invalid syntax

Tags: path方法name数据库sourcehellodbsqlite