我正在尝试在表中插入一些值,虽然正在创建行,但没有记录这些值。这是我的代码:
for i in range(2,6):
for team in ul[i]:
name = team.string #string from html element
print(name) #this works just fine, and prints the desired name
cur.execute("INSERT INTO teams (Name) VALUES(name)")
conn.commit()
现在,如果我VALUES("Test String")
改为使用它,它会添加 30 行(我想要的),并且所有行都带有名称:“测试字符串”。
然而,当我放入我的name
变量时,行也被添加,但列值是空的。我将字符串放入的列是VARCHAR
. 在 Python 字符串变量的情况下,SQL 语句是如何解释的,有什么我不知道的吗?