如何将列添加到sqlite3 python?

use*_*071 8 python sqlite

我知道这很简单,但我不能让它工作!我没有插入,更新或选择命令的probs,让我说我有一个字典,我想用字典中的列名填充一个表,我添加一行的一行有什么问题?

##create
con = sqlite3.connect('linksauthor.db')
c = con.cursor()
c.execute('''create table linksauthor (links text)''')
con.commit()
c.close()
##populate author columns
allauthors={'joe':1,'bla':2,'mo':3}
con = sqlite3.connect('linksauthor.db')
c = con.cursor()
for author in allauthors:
    print author
    print type(author)
    c.execute("alter table linksauthor add column '%s' 'float'")%author  ##what is wrong here?
    con.commit()
c.close()
Run Code Online (Sandbox Code Playgroud)

bal*_*pha 15

你的paren是错位的.你可能意味着这个:

c.execute("alter table linksauthor add column '%s' 'float'" % author)
Run Code Online (Sandbox Code Playgroud)