Question

Is there actually a way of doing this? I've tried using the following code:

file_path = os.environ['APPDATA'] + "\\Example\\example.db" sqlite3.connect(file_path)

But it comes up with an error. My only thought would be that it's permissions-related, but if that was the case, then I probably wouldn't create a file there, either... I'm stumped. Anyone got any idea?

Was it helpful?

Solution

Try like this,

import os
dir_path = '%s\\Example\\' %  os.environ['APPDATA'] 
if not os.path.exists(dir_path):
    os.makedirs(dir_path)

file_path = '%sexample.db' % dir_path
sqlite3.connect(file_path)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top