【发布时间】:2013-07-11 21:44:15
【问题描述】:
我遇到了一个奇怪的问题。我有一个返回布尔值的方法。反过来,我需要再次返回该函数的结果,因为我不能直接从前端调用该方法。这是我的代码:
# this uses bottle py framework and should return a value to the html front-end
@get('/create/additive/<name>')
def createAdditive(name):
return pump.createAdditive(name)
def createAdditive(self, name):
additiveInsertQuery = """ INSERT INTO additives
SET name = '""" + name + """'"""
try:
self.cursor.execute(additiveInsertQuery)
self.db.commit()
return True
except:
self.db.rollback()
return False
这会抛出异常:TypeError("'bool' object is not iterable",)
我根本没有收到此错误,因为我没有尝试“迭代”布尔值,只是返回它。
如果我返回一个字符串而不是 boolean 或 int,它会按预期工作。这可能是什么问题?
追溯:
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\bottle.py", line 821, in _cast
out = iter(out)
TypeError: 'bool' object is not iterable
【问题讨论】:
-
请发布整个回溯。
-
查看完整追溯编辑。
标签: python python-3.x bottle