【问题标题】:web.py db.insert function throw error : <type 'exceptions.TypeError'> : 'long' object is unsubscriptableweb.py db.insert 函数抛出错误:<type 'exceptions.TypeError'>:'long' 对象不可订阅
【发布时间】:2011-08-06 13:45:26
【问题描述】:

我有一个名为 foo 的数据库(mysql)表,它的主键是 bigint 类型,并且自动递增, 我编写以下代码来插入记录并获取记录的主键

q = db.insert('foo', name='bob', age=2, _test=True)
print q

这条记录已插入到表中,但出现以下错误:

type 'exceptions.TypeError' : 'long' 对象不可订阅

你能帮我做什么吗?

【问题讨论】:

    标签: python mysql sql database web.py


    【解决方案1】:

    当您尝试将__getitem__ 接口用于不支持它的对象时,您会收到TypeError: '&lt;type&gt;' object is not subscriptable 错误。这通常看起来像这样container[...]

    查看完整的回溯。在某处,您应该会看到以这种方式访问​​的对象。由于您没有显示完整的回溯或其余代码,因此我无法告诉您在哪里。

    【讨论】:

      【解决方案2】:

      我怀疑问题出在打印 q web.py的文档中没有提到它

      >>> db = DB(None, {})
      >>> q = db.insert('foo', name='bob', age=2, created=SQLLiteral('NOW()'), _test=True)
      >>> q
      <sql: "INSERT INTO foo (age, name, created) VALUES (2, 'bob', NOW())">
      >>> q.query()
      'INSERT INTO foo (age, name, created) VALUES (%s, %s, NOW())'
      >>> q.values()
      [2, 'bob']
      

      【讨论】:

        猜你喜欢
        • 2022-11-25
        • 1970-01-01
        • 2023-02-03
        • 1970-01-01
        • 2018-01-23
        • 2020-01-06
        • 2018-04-29
        • 2022-12-11
        • 1970-01-01
        相关资源
        最近更新 更多