AttributeError:'聊天'对象没有属性' converse'

时间:2016-04-29 07:30:57

标签: python attributeerror

#SLINNINGBOT 2.0#

import nltk.chat
import sys
import os
import time
import platform
from nltk.chat.util import Chat, reflections
import re
import random
from nltk import compat

what = platform.system()
now = time.time()
means = time.ctime(now)



class Chat(object):
    def converse(self, quit="quit"):
            input = ""
            while input != quit:
                input = quit
                try: input = compat.raw_input(">")
                except EOFError:
                    print(input)
                if input:
                    while input[-1] in "!.": input = input[:-1]
                    print(self.respond(input))

    slinning_chatbot = Chat(pairs, reflections)

    def slinning_chat():
        print "WELCOME"
        print "OPERATIONAL SYSTEM:",what
        print "\nTIME IS NOW",now
        print "WHICH INTERPRETS AS",means
        print "PLEASE BE AWARE THAT THIS BOT IS UNDER DEVELOPMENT AND MAY BE FAULTY"
        print"======================================================================="
        print"Please fill the input"

        slinning_chatbot.converse()
    def demo():
        slinning_chat()
    if __name__ == "__main__":
        demo()

我刚刚提取了我认为在这里真正重要的代码部分,我不知道为什么会出现错误:AttributeError:' Chat'对象没有属性' converse'

如果您需要整个代码,请打我,但很长时间

2 个答案:

答案 0 :(得分:0)

您的代码在完全定义Chat类之前执行,因此它正在尝试使用nltk.chat.util.Chat。在定义类之后,确定要运行的部分,并避免重用名称。

答案 1 :(得分:0)

发生这种情况的原因是因为导入与类冲突,因为它们具有相同的名称