[英]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.