Python Sqlite3 Get Sqlite Connection path

后端 未结 3 790
囚心锁ツ
囚心锁ツ 2021-02-18 17:59

Given an sqlite3 connection object, how can retrieve the file path to the sqlite3 file?

3条回答
  •  离开以前
    2021-02-18 18:39

    Referencing Martijn Pieters, except hardcoding is a must, you should do this:

    path = os.path.dirname(os.path.abspath(__file__))
    db = os.path.join(path, 'file.db')
    
    conn = sqlite3.connect(db)
    

提交回复
热议问题