my application uses SQLite database for it’s data storage. Idelly, this database should reside on some network drive, let’s name it Z: (Windows XP’s “Map network drive” feature).
Application is being developed under Linux, with database locally stored. Here is a part of one module:
import sqlite3 as lite con = lite.connect("base.db")
What would be the correct way to access database on Z: drive? Something along the lines of:
import sqlite3 as lite import os path = 'Z:' con = lite.connect(path+"base.db")
Advertisement
Answer
You should use os.path.join
to create your path, since it will use the correct path seperator. Also, you can use os.name
to check if you’re running on windows:
filename = 'base.db' path = os.path.join('z:/', filename) if os.name == 'nt' else filename con = lite.connect(path)
Nonetheless, you probably want to make the file location configurable to make it easier to develop/debug/deploy your application.