简单的聊天机器人在Anaconda / Python中产生错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单的聊天机器人在Anaconda / Python中产生错误相关的知识,希望对你有一定的参考价值。
我复制了这个小的Python代码用于聊天机器人。
from nltk.chat.util import Chat, reflections
pairs = [
[
r"my name is (.*)",
["Hello %1, How are you today ?",]
],
[
r"what is your name ?",
["My name is Chatty and I'm a chatbot ?",]
],
[
r"how are you ?",
["I'm doing good\nHow about You ?",]
],
[
r"what (.*) want ?",
["Make me an offer I can't refuse",]
],
]
my_dummy_reflections=
"go" : "gone",
"hello" : "hey there"
def chatty():
print("Hi, I'm Chatty and I chat alot ;)\nPlease type lowercase English language to start a
conversation. Type quit to leave ") #default message at the start
#chat = Chat(pairs, reflections)
chat = Chat(pairs, my_dummy_reflections) #THIS IS THE PROBEM!!
chat.converse()
if __name__ == "__main__":
chatty()
我得到的错误代码是:
File "<tokenize>", line 87
chat = Chat(pairs, my_dummy_reflections)
IndentationError: unindent does not match any outer indentation level
我不了解Python中的问题。它位于脚本的结尾,涉及具有2个参数的CHAT函数...感谢您的帮助!
答案
Python使用缩进,您应该read about it更好地理解它。
因此基本上在第28行中,缺少选项卡。
它是:
if __name__ == "__main__":
chatty()
应该是:
if __name__ == "__main__":
chatty()
以上是关于简单的聊天机器人在Anaconda / Python中产生错误的主要内容,如果未能解决你的问题,请参考以下文章
简单记录下卸载重装Anaconda、装PANDAS包及Anaconda笔记