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?
Answers:
Try setting the filename without the quotes:
filename = optionMenuWidget.cget
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?
Try setting the filename without the quotes:
filename = optionMenuWidget.cget