[英]How to print a table in sqlite3 along with column names in python using a loop and how exactly to get the column names?
[英]How do I pass variables as column and table names in a python sqlite3 command?
我正在尝试将表名和列名传递给 python 中的 sqlite 命令。 据我了解,这是无法通过传统方法完成的。
conn.execute('ALTER TABLE ? ADD COLUMN ?;', t)
我试过了
{}.format
":X",(X: t)
和其他一些人,任何帮助将不胜感激
使用str.format
:
conn.execute('ALTER TABLE {} ADD COLUMN {};'.format(table, column))
或者,如果您使用的是 Python 3.6+,则可以使用 f-strings:
conn.execute(f'ALTER TABLE {table} ADD COLUMN {column};')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.