你能在googleappengine中使用pydictionary吗?

2024-09-27 09:36:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图在googleappengine应用程序中使用pyDictionary,但出现了一个错误。当我在google应用程序之外使用它时,我不会得到这个错误。我已经添加了它作为第三方库(正确的),所以它实际上导入它没有错误,所以我不知道为什么。你知道吗

错误如下:

searching.py", line 63, in   getkey assert isinstance(word.keys, object)

AttributeError: 'NoneType' object has no attribute 'keys'

下面是该函数的代码:

def getkey(term):
    dictionary = PyDictionary()
    word = dictionary.meaning(term)
    assert isinstance(word.keys, object)
    results = word.keys()
    newresults = []
    for result in results:
        newresults.append(str(result))
    return newresults[0]

它在appengine项目外部工作,但在内部不工作。。。你知道吗


Tags: in应用程序dictionaryobject错误assertresultkeys
1条回答
网友
1楼 · 发布于 2024-09-27 09:36:47

你应该回头看看你的异常,试着理解它告诉你什么。你知道吗

searching.py", line 63, in   getkey assert isinstance(word.keys, object)

AttributeError: 'NoneType' object has no attribute 'keys'

让我们追溯到你的代码。你知道吗

因为发生错误意味着word引用的值是None。你知道吗

这意味着word = dictionary.meaning(term)的结果

None。你知道吗

所以你应该看看term的值是多少。你知道吗

你在验证term在任何地方都是有意义的吗?如果是,那么dictionary.meaning(term)的预期结果是什么,然后调查为什么没有得到预期结果。你知道吗

一些基本的调试可以帮助您诊断问题。你知道吗

相关问题 更多 >

    热门问题