How to define a db file for sqlite?
sjmachin at lexicon.net
Sun Mar 8 08:57:13 CET 2009
On Mar 8, 6:32 pm, Muddy Coder <cosmo_gene... at yahoo.com> wrote:
> Hi Folks,
> I just downloaded and installed pysqlite, and I can import sqlite3
> smoothly. Then, I need to connect sqlite by syntax:
> >>>conn = sqlite3.connect('adirectory/db')
> I wish the data will be stored into directory ---> adirectory, with a
> file named in db. But I got kicked out with an error message as:
> Unable to open database file
> I wonder: does pysqlite open a database file db for me?
Yes, provided that "adirectory" exists and you have write permission.
It won't make a directory for you. Same applies to open('adirectory/
Ensure that adirectory exists, and try it again. If that fails, try
the open() -- you may get a more informative error message.
> Or, do I need
> to create an empty file inside adirectory with my text editor?
No. However, try that and remember what happens.
More information about the Python-list