How to define a db file for sqlite?

Discussion in 'Python' started by Muddy Coder, Mar 8, 2009.

  1. Muddy Coder

    Muddy Coder Guest

    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? Or, do I need
    to create an empty file inside adirectory with my text editor? Anyway,
    somebody please help me out here. After I can connect it, the rest
    will be easy to go, thanks!

    Muddy coder
     
    Muddy Coder, Mar 8, 2009
    #1
    1. Advertising

  2. Muddy Coder

    John Machin Guest

    On Mar 8, 6:32 pm, Muddy Coder <> 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/
    db', 'wb')

    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.
     
    John Machin, Mar 8, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. theotyflos
    Replies:
    3
    Views:
    474
    Thomas Matthews
    Feb 19, 2004
  2. robin liu
    Replies:
    3
    Views:
    824
    Robin Liu
    Apr 21, 2006
  3. Carl Youngblood
    Replies:
    1
    Views:
    232
    Carl Youngblood
    Apr 9, 2005
  4. Brian Takita

    #define _ and #define __

    Brian Takita, Jan 23, 2006, in forum: Ruby
    Replies:
    0
    Views:
    467
    Brian Takita
    Jan 23, 2006
  5. Replies:
    4
    Views:
    351
Loading...

Share This Page