试着在python shell中使用sqlite

1 python sqlite

我刚刚得到python并输入:

sqlite test.db

..在shell中,但是我得到了语法错误....我错过了什么?

soe*_*ace 7

我想你做了以下事情?

$ 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
Run Code Online (Sandbox Code Playgroud)

试试这个:

import sqlite3
conn = sqlite3.connect('test.db')
cursor = conn.cursor()
cursor.execute('''Your query goes here''')
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请查看python2python3的sqlite文档