V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
tangyuan
V2EX  ›  问与答

sqlite fetchall返回对象无法被遍历

  •  
  •   tangyuan · 2013-02-03 10:24:29 +08:00 · 3366 次点击
    这是一个创建于 4114 天前的主题,其中的信息可能已经有所发展或是发生改变。
    请教一个小问题

    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-02-03 10:39:48 +08:00   ❤️ 1
    - -都说records是一个方法对象了,回去检查下,发现是不是少了点什么呢
    tangyuan
        2
    tangyuan  
    OP
       2013-02-03 10:48:40 +08:00
    原来少写了个()...fetchall instead of fetchall()
    晕死...感谢best1a
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1140 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 18:52 · PVG 02:52 · LAX 11:52 · JFK 14:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.