Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating database file one directory above current

Tags:

python

sqlite

In PHP, To refer to a higher directory I would use '../../test'; How would I do it in Python?

In this case, I'm using SQLite to create a database file.

import sqlite3
conn = sqlite3.connect('../data/test.db')

However; it says 'unable to open database file' which I'm considering as a directory access error. How do I refer to higher directory in Python?

like image 605
Oliver Kucharzewski Avatar asked Jan 31 '26 02:01

Oliver Kucharzewski


1 Answers

You might try this:

conn = sqlite3.connect(os.path.realpath('../data/test.db'))
like image 83
gview Avatar answered Feb 02 '26 17:02

gview



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!