tangyuan
V2EX  ›  问与答

sqlite fetchall返回对象无法被遍历

By tangyuan at 2013 年 2 月 3 日 · 4159 次点击
请教一个小问题

c.execute("SELECT local_code FROM db WHERE priority LIKE ?", (1,))
records = c.fetchall

我通过fetchall拿到了如下这个对象
<built-in method fetchall of sqlite3.Cursor object at 0x02C5E6A0>

但在view里面遍历打算将其显示出来的时候报错被告知
%for row in records:
<p>row</p>
%end

%for row in records:
TypeError: 'builtin_function_or_method' object is not iterable
2 条回复  •  1970-01-01 08:00:00 +08:00
best1a
   1
best1a  
   2013 年 2 月 3 日   ❤️ 1
- -都说records是一个方法对象了,回去检查下,发现是不是少了点什么呢
tangyuan
   2
tangyuan  
OP
   2013 年 2 月 3 日
原来少写了个()...fetchall instead of fetchall()
晕死...感谢best1a
© 2026 V2EX · 25ms · 3.9.8.5