I created a database with sqlite3 and I want to open it in DB Browser. Problem is I have no idea where to find the database so I can open it there. And when I look in my 'sqlite3' directory under conda (I'm doing all this in jupyternotebook), I can't find any databases I created.
I can run other commands with this database I created so I know it exists. I just don't know where it's located.
import sqlite3 as sql
conn = sql.connect('z')
cur = conn.cursor()
x = cur.execute('''SELECT year FROM z;''').fetchall()
print(x)
conn.close()
This works as a query, but I don't know where "z" is located. How do I find whre z is stored?
I'm not sure if this is a coding question, but if it isn't, then could someone tell me where to go for questions like this?
CodePudding user response:
import os
print(os.path.abspath('z'))
or
print(conn.execute("SELECT file FROM pragma_database_list WHERE name = 'main';").fetchone()[0])
CodePudding user response:
conn = sql.connect('z')
You are creating a database in memory called "z". This is why the database works when you're running the script but you cannot find it in DB Browser, because you never created a .db file in your directory.