How to put string from function as an argument for sqlite3.connect() in python

Question:

I have option menu widget:

optionTuple = ("filename1", "filename2", "filename3")

filename1, filename2, filename3 are also names of files in directory

then I have button which inter alia gets selected option value:

def btnConvertClick(self):
    filename = '"'+ optionMenuWidget.cget('text')+'"'

then I try to open [sqlite3]database file [filename1 or filename2 or filename3] according to selected option

selected_file = filename
db = sqlite3.connect(selected_file)

but I get error:

<class 'sqlite3.OperationalError'>: unable to open database file

I have no problem with:

db = sqlite3.connect("filename1")

Is it possible to put string from function [as above] as filename argument?

Asked By: daikini

||

Answers:

Try setting the filename without the quotes:

filename = optionMenuWidget.cget
Answered By: ennuikiller
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.