Skip to main content
 首页 » 编程设计

python之尝试将 sqlite 与 python shell 一起使用

2025年05月04日17tintown

我刚得到 python 并输入:

sqlite test.db 

进入 shell,但出现语法错误。我错过了什么?

请您参考如下方法:

我猜你做了以下事情?

$ 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''') 

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