![](/img/trans.png)
[英]How do i select the value of a certain column from the last row in sqlite3 and python?
[英]How do I select a column by its name? (Python & SQLite3)
目前我有以下代碼:
c.execute("SELECT * FROM table")
for row in c.fetchall():
print row[0]
print row[1]
但是,我更改了表的結構,現在我必須更改索引值以表示此更改。 有沒有辦法獲得使用列名?
因此,建議在執行SELECT
時始終使用顯式列名:
c.execute("SELECT color, fluffiness FROM table")
for row in c.fetchall():
print row[0] # <-- is always guaranteed to be the color value
print row[1]
請參閱sqlite3模塊的文檔中的行對象 。 如果你使用sqlite3.Row
row_factory,你將獲得一個比普通元組稍強大的對象。 我想它的開銷略高,因此不是默認行為。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.