2

I just got python and typing:

sqlite test.db

into the shell, but I get a syntax error. What have I missed?

2
  • I think you missed reading the documentation, especially the Python language tutorial. Try that first. Commented Dec 31, 2012 at 0:42
  • sqlite test.db is valid command in cmd or terminal not in python shell Commented Dec 31, 2012 at 1:22

4 Answers 4

8

I guess that you did the following?

$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> sqlite test.db
  File "<stdin>", line 1
    sqlite test.db
              ^
SyntaxError: invalid syntax

Try this instead:

import sqlite3
conn = sqlite3.connect('test.db')
cursor = conn.cursor()
cursor.execute('''Your query goes here''')

For more details, take a look at the sqlite documentation for python2 or python3

Sign up to request clarification or add additional context in comments.

Comments

2

Python doesn't provide this command-line utility so make sure sqlite3 is in your path. Then you can either execute:

$ sqlite3 mydb.db

or if you have entered your settings in settings.py:

./manage.py dbshell

Comments

0

I think you want to use the sqlite3 command line tool to create a new database. For this you should use your system terminal not the python console. So the command should look like so (on a linux system):

$ sqlite3 test.db

Comments

0

Verify if sqlite exist in PATH and what are privileges for file test.db.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.