0
pymssql에서 행을 사전으로 수신하려고합니다. 파이썬 유휴에 내가 도망 :사전으로 행 - pymssql
>>> conn = pymssql.connect(host='192.168.1.3', user='majid', password='123456789', database='GeneralTrafficMonitor', as_dict=True)
>>> cur = conn.cursor()
>>> cur.execute('SELECT TOP 10 * FROM dbo.tblTrafficCounterData')
>>> cur.as_dict
True
>>> for row in cur:
print row['ID']
그러나 제공합니다
Traceback (most recent call last):
File "<pyshell#83>", line 2, in <module>
print row['ID']
TypeError: tuple indices must be integers, not str
누군가가 도와 주 시겠어요?
as_dict 지원으로 __iter __()가 남았을 수 있습니다. fetchall()이 as_dict를 지원한다는 명시적인 문서이므로 cur.fetchall()의 행에도 동일하게 사용하십시오. 그건 좀 바보 같지만 절대로 몰라요. – jpic