# coding: utf-8 import sqlite3 conn = sqlite3.connect(r'E:\dev\sqlite-test\test1.db') c = conn.cursor() c.execute("select * from syain") list1 = c.fetchone() print (list1) #(1, '鈴木', 'suzuki') print (list1[0]) # 1 print (list1[1]) # 鈴木' print (list1[2]) # suzuki conn.close()
ネタ元
itertuplesを使う方法もある
itertuplesを使うと行毎にindexやカラム名、値をタプルで取得できる。
for t in df.itertuples(): print(t) >> Pandas(Index=0, colA=1, colB='a', colC=5) Pandas(Index=1, colA=2, colB='b', colC=6) Pandas(Index=2, colA=3, colB='c', colC='e') Pandas(Index=3, colA=4, colB='d', colC='f')