Python sqlite:将值插入表,表名为variable

时间:2018-02-24 16:33:07

标签: python sql sqlite

我在下面更改我的代码时遇到了一些问题。我想用变量替换表名。有什么建议?

c.execute("INSERT INTO budget VALUES (  \
    :date,  \
    :time,  \
    :amount,  \
    :balance,  \
    :balance_EUR  \
    )",  \
    {
     'date': line_list[i*5+0],  \
    'time': line_list[i*5+1], \
    'amount': line_list[i*5+2], \
    'balance': line_list[i*5+3],  \
    'balance_EUR': line_list[i*5+4]  \
    }) 

我尝试了下面的代码但是没有用。

c.execute("INSERT INTO VALUES {} (  \
    :date,  \
    :time,  \
    :amount,  \
    :balance,  \
    :balance_EUR  \
    )".format('table_name'),  \
    {
     'date': line_list[i*5+0],  \
    'time': line_list[i*5+1], \
    'amount': line_list[i*5+2], \
    'balance': line_list[i*5+3],  \
    'balance_EUR': line_list[i*5+4]  \
    }) 

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

您的字符串格式参数位于字符串中的错误位置。将其更改为

GOOS=linux go build -o hello .