|
try:
parent = self._elemStack[-1][0]
parentAttr = self._elemStack[-1][1]
required, optional, canBeParent = self._validInfo[parent]
问题定位到如上所示,运行时报错如下:
File "F:\PyCharmWorkplaces\pyaiml\aiml\AimlParser.py", line 280, in _characters
required, optional, canBeParent = self._validInfo[parent]
KeyError: b'learn'
Process finished with exit code 1
可以看出,parent对应的是b'learn',工作目的是希望parent对应‘learn’,不要前缀b!
于是就想去掉b,做了一个小测试,代码如下:
parent = b'learn'
parent = parent.decode('utf-8')
print(parent)
运行结果为:learn
Process finished with exit code 0
于是修改为:
try:
parent = self._elemStack[-1][0].decode('utf-8')
parentAttr = self._elemStack[-1][1]
required, optional, canBeParent = self._validInfo[parent]
接着报错:
File "F:\PyCharmWorkplaces\pyaiml\aiml\AimlParser.py", line 278, in _characters
parent = self._elemStack[-1][0].decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'
Process finished with exit code 1
如果改为:
try:
parent = self._elemStack[-1][0].encode('utf-8')
parentAttr = self._elemStack[-1][1]
required, optional, canBeParent = self._validInfo[parent]
错误如下:
File "F:\PyCharmWorkplaces\pyaiml\aiml\AimlParser.py", line 280, in _characters
required, optional, canBeParent = self._validInfo[parent]
KeyError: b'template'
Process finished with exit code 1
发现此时,parent对应为b'template'
卒。。。
希望大佬们帮我复活。
|
|