tangyuan
V2EX  ›  问与答

sqlite fetchall返回对象无法被遍历

  •  
  •   tangyuan · Feb 3, 2013 · 3832 views
    This topic created in 4847 days ago, the information mentioned may be changed or developed.
    请教一个小问题

    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 replies    1970-01-01 08:00:00 +08:00
    best1a
        1
    best1a  
       Feb 3, 2013   ❤️ 1
    - -都说records是一个方法对象了,回去检查下,发现是不是少了点什么呢
    tangyuan
        2
    tangyuan  
    OP
       Feb 3, 2013
    原来少写了个()...fetchall instead of fetchall()
    晕死...感谢best1a
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1393 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 17:06 · PVG 01:06 · LAX 10:06 · JFK 13:06
    ♥ Do have faith in what you're doing.