我不知道我的代码中到底有什么错误

2024-04-24 10:30:19 发布

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

我运行了一个包含.xml扩展名文件和python文件的简单代码。我得到的错误如图所示。我不知道背后的主要原因,也不知道如何纠正它。 显示的错误是:

Loading brain from startup.xml...Error restoring PatternMgr from file startup.xml:
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    kernel.bootstrap(brainFile="startup.xml")
  File "C:\Users\adith\AppData\Local\Programs\Python\Python37\lib\site-packages\aiml\Kernel.py", line 134, in bootstrap 
    self.loadBrain(brainFile)
  File "C:\Users\adith\AppData\Local\Programs\Python\Python37\lib\site-packages\aiml\Kernel.py", line 194, in loadBrain 
    self._brain.restore(filename)
  File "C:\Users\adith\AppData\Local\Programs\Python\Python37\lib\site-packages\aiml\PatternMgr.py", line 67, in restore
    self._templateCount = marshal.load(inFile)
ValueError: bad marshal data (unknown type code)

文件a.xml

<aiml version="1.0.1" encoding="UTF=8">
    <category>
        <patern>HELLO THERE</pattern>
        <template>
            i am hitler!!!!!!!
        </template>
    <category>
</aiml>

文件b.xml

<aiml version="1.0.1" encoding="UTF=8">
    <category>
        <patterrn> I am *</pattern>
        <template>
            thats interesting that your dog name is<set name="dog"><star/></set>
        </template>
    </category>
    <category>
        <pattern> WHAT IS MY DOGS NAME </pattern>
        <template> 
            your name is : <get name="dog"/>
        </template>
    </category>
</aiml>

文件c.xml

<aiml version="1.0.1" encoding="UTF=8">
    <category>
        <pattern>LETS DISCUSS MOVIES</pattern>
        <template>yes<set name="topic">movies</set></template>
    </category>
    <category>
        <pattern>LETS DISCUSS GAMES</pattern>
        <template>yes<set name="topic">games</set></template>
    </category>
    <topic name ="MOVIES">
        <category> 
            <pattern>SUGGEST</pattern>
            <template> Batman</template>
        </category>
    </topic>
    <topic name ="GAMES">
        <category> 
            <pattern>SUGGEST</pattern>
            <template> Pacman</template>
        </category>
    </topic>
</aiml>

文件startup.aiml

<aiml version="1.0.1" encoding="UTF=8">
    <!--std-startup.xml -->
    <!-- Category is an atomic AIML unit -->
    <category>
        <pattern> LOAD *</pattern>
        <template>
            <learn> <star>.xml</learn>
        </template>
    <category>
</aiml>

文件test.py

import aiml
import os
kernel=aiml.Kernel()
if os.path.isfile("bot_brain.brm"):
    kernel.bootstrap(brainFile="bot_brain.brn")
else:
    kernel.bootstrap(brainFile="startup.xml")
I=input(">>>>>")
while I!="exit()":
    print(kernel.respond(I))
    I=input(">>>>>")
kernel.saveBrain("bot_brain.brn")

Tags: 文件namepytopiclinetemplatexmlkernel