Python 如何使用存储在变量中的值创建或打开数据库

Python 如何使用存储在变量中的值创建或打开数据库,python,sqlite,Python,Sqlite,我正在使用sqlite在数据库中存储一些值,但这些值来自不同的源,因此我必须将它们放在不同的数据库中,因此我尝试了以下方法: source_name = "hello" ext = ".db" path = "d:/" fullpath = path + source_name + ext db = sqlite3.connect("%s") % (fullpath) 但它不起作用,没有任何解决方案或想法 报告的错误是: %引号内的s: TypeError: unsupported

我正在使用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
str.\uuuu mod\uuuuu()
str
上的一种方法:

db = sqlite3.connect("%s" % fullpath)
或者因为
fullpath
已经是一个字符串:

db = sqlite3.connect(fullpath)