Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Database Error

Tags:

python

sqlite

When I put my database file (which is a .sdb) into a directory and try to access it from that directory, I receive an error. The error reads "unable to open database file". For example, let's say my .sdb file is in the "data" directory and I use the command "con = lite.connect('data\noktalar.sdb')", this error occurs. Why is that so?

Thanks.

like image 442
Shansal Avatar asked Jul 25 '26 01:07

Shansal


1 Answers

\ is the escape character in python strings. You have to use double backslashes:

con = lite.connect('data\\noktalar.sdb')

Or like Senthil said, use raw strings:

con = lite.connect(r'data\noktalar.sdb')

For more information, check the Python doc about string literals.

like image 121
Wang Dingwei Avatar answered Jul 27 '26 15:07

Wang Dingwei



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!