我正在做一个项目,它使用sqlite3数据库来存储一些数据。在
我的搜索函数使用SQL语句:'''SELECT text FROM snippets WHERE title=?''', (whichName,)
,正如我的代码所示,whichName
作为一个字典出现,这导致了以下错误:
Traceback (most recent call last):
File "snippets.py", line 93, in <module>
main()
File "snippets.py", line 24, in main
get_value_from_name(response)
File "snippets.py", line 58, in get_value_from_name
(whichName,))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
因此,我认为我需要将它作为字符串传递,所以我只是name = str(response)
将其转换为字符串,但问题就从这里开始了。它给了我这个:
当我把字典转换成字符串时。然后搜索函数返回None
,因为它是按[u'TEST']
而不是{
translation_table = dict.fromkeys(map(ord, '(),'), None)
# Above code creates a table with the mapped characters
name = str(response)
name = name.translate(translation_table)
这就是我目前的问题所在。它返回以下错误:
Traceback (most recent call last):
File "snippets.py", line 93, in <module>
main()
File "snippets.py", line 20, in main
name = name.translate(translation_table)
TypeError: expected a character buffer object
我看了这些问题:
Python TypeError: expected a character buffer object, personal misunderstanding-不适用于我的问题
expected buffer object error on string.translate - python 2.6-也不适用,因为我的翻译表是从字符串而不是字典创建的
Getting error "expected character buffer object" and I don't know why-也不适用,因为他正试图在索引处执行此操作。我试着做它应该做的,找到/替换整个字符串。
但没有一个适用于我的问题(据我所知)
有人知道是什么导致了类型错误吗?在
谢谢!在
我解决了这个问题。我在python3.3.2+中运行了代码,它的工作原理是find(尽管对翻译表做了一些小的调整)
对不起,如果我浪费了别人的时间。我会尽快将此标记为答案。在
相关问题 更多 >
编程相关推荐