1

我刚得到python并输入:

sqlite test.db

..进入外壳,但出现语法错误..我错过了什么?

4

4 回答 4

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

试试这个:

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

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

于 2012-12-31T00:20:33.497 回答
1

Python 不提供此命令行实用程序,因此请确保sqlite3在您的路径中。然后你可以执行:

$ sqlite3 mydb.db

或者,如果您在 settings.py 中输入了设置

./manage.py dbshell
于 2013-06-20T18:33:29.103 回答
0

验证 PATH 中是否存在 sqlite 以及文件 test.db 的权限是什么

于 2012-12-31T00:20:02.023 回答
0

我想你想使用 sqlite3 命令行工具来创建一个新的数据库。为此,您应该使用系统终端而不是 python 控制台。所以命令应该看起来像这样(在 linux 系统上):

$ sqlite3 test.db
于 2012-12-31T00:25:35.043 回答