jeudi 11 juin 2015

How to create or open a database with a value stored in a variable

I'm using sqlite to store some values in a database , but the values are from different source so i have to put them in different database so i tried something like:

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

but it didn't work, any solutions or ideas.

The error reported was :

%s within quotes :

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

%s without quotes :

 SyntaxError: invalid syntax

Aucun commentaire:

Enregistrer un commentaire