在添加我的程序功能之前,它可以在我的sqlite3 db中运行并打印出我的命令
但是在添加def之后
看起来像
def readswitch(x,y,read):
x='create vlan'
y='global'
conn = sqlite3.connect('server.db')
with conn:
cur = conn.cursor()
# function = "SELECT command FROM switch WHERE function =:function or type =:type ORDER BY key ASC",{"function":x},{"type":y}
# function = ("SELECT command FROM switch WHERE function =? or type = ? ORDER BY key ASC",(x,y))
cur.execute("SELECT command FROM switch WHERE function =? or type = ? ORDER BY key ASC",(x,y))
read = cur.fetchall()
for row in read:
print (readswitch())
它显示x='create vlan'IndentationError: expected an indented block
按下标签后按空格键
它有这样的错误:
def readswitch(x,y,read):
x='create vlan'
y='global'
conn = sqlite3.connect('server.db')
with conn:
cur = conn.cursor()
# function = "SELECT command FROM switch WHERE function =:function or type =:type ORDER BY key ASC",{"function":x},{"type":y}
# function = ("SELECT command FROM switch WHERE function =? or type = ? ORDER BY key ASC",(x,y))
cur.execute("SELECT command FROM switch WHERE function =? or type = ? ORDER BY key ASC",(x,y))
read = cur.fetchall()
for row in read:
print (readswitch())
cur.execute("SELECT command FROM switch WHERE function =? or type = ? ORDER BY key ASC",(x,y))
NameError: name 'x' is not defined
我现在该怎么办?
现在我解决了这个问题 并面临其他功能错误
我删除def(readswitch(x,y,read):
它没有错误,可以打印出我的命令。
x='create vlan'
y='global'
conn = sqlite3.connect('server.db')
if conn:
cur = conn.cursor()
cur.execute("SELECT command FROM switch WHERE function =? or type = ? ORDER BY key ASC",(x,y))
read = cur.fetchall()
for row in read:
print (row)
# def update()
但在我添加def(readswitch(x,y,read):
之后我改变了print(row):
什么都不打印
def readswitch(x,y,read):
x='create vlan'
y='global'
conn = sqlite3.connect('server.db')
if conn:
cur = conn.cursor()
cur.execute("SELECT command FROM switch WHERE function =? or type = ? ORDER BY key ASC",(x,y))
read = cur.fetchall()
for row in read:
print (readswitch())
任何人都有一些想法吗? `
答案 0 :(得分:0)
某些陈述的缩进问题是错误的。
def readswitch(x,y,read):
x='create vlan'
y='global'
conn = sqlite3.connect('server.db')
if conn:
cur = conn.cursor()
cur.execute("SELECT command FROM switch WHERE function =? or type = ? ORDER BY key ASC",(x,y))
read = cur.fetchall()
for row in read:
print row