本文介绍了SQL Alchemy 返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 session.query().filter 查询表.我得到如下输出:(u'1234').但是当我尝试使用 str.translate(None, '5) 翻译它时,它会引发错误
I am querying the table using session.query().filter. I get an output like: (u'1234'). But when I try to translate this using str.translate(None, '5), it throws an error
KeyedTuple' object has no attribute 'translate'我哪里出错了?
推荐答案你得到一个包含一个元素的元组.在对它使用 result_string.translate 之前,您必须先检索这个元素.
You get a tuple with one element. You have to retrieve this one element first before using result_string.translate on it.
如果您将 session.query().filter 的返回值保存在变量 result 中,请执行
If you save the return of your session.query().filter inside a variable result do
if result: # Check that result is not empty result[0].translate(...)更多推荐
SQL Alchemy 返回类型
发布评论