Python 2.7 操作错误:接近“&引用;:语法错误sqlite3错误
我试图通过调用文件的函数在表中添加两个值。该文件包含以下代码:Python 2.7 操作错误:接近“&引用;:语法错误sqlite3错误,python-2.7,sqlite,Python 2.7,Sqlite,我试图通过调用文件的函数在表中添加两个值。该文件包含以下代码: import sqlite3 con = sqlite3.Connection('rdb') cur = con.cursor() def insert(s): cur.execute("create table if not exists customerorder(no number primary key,menuitems varchar(40))") c=1 for i in s:
import sqlite3
con = sqlite3.Connection('rdb')
cur = con.cursor()
def insert(s):
cur.execute("create table if not exists customerorder(no number primary
key,menuitems varchar(40))")
c=1
for i in s:
print c
print i
cur.execute("insert into customerorder(?,?)",(int(c),i))
c += 1
def fetch():
cur.execute("select * from customerorder")
print cur.fetchall()
这是一份清单。
有s[0]=“简单书”和s[1]=“高级书”
你需要把它改成
insert into customerorder values(?,?)
表名后面的parens中的第一个列表是列列表,列名不能有?
变量
insert into customerorder values(?,?)