0
我想在pymssql中以字典的形式接收行。在python空閒,我跑:行作爲詞典 - 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
有人能幫忙嗎?
也許__iter __()是as_dict支持的剩餘部分,請嘗試與cur.fetchall()中的row相同,因爲文檔是顯式的,fetchall()支持as_dict。這聽起來有點愚蠢,但你永遠不知道...... – jpic 2012-04-02 08:25:55