请问我在写txt的时候
f = open("p/text/Reply.txt","w") #设置文件对象
f.write(str(response))
为什么报错
自己解决了,把.pyw改成.py即可
这部分代码是没有问题的,能否把代码沾全看看
try:
import easygui as g
import sys,os
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
f = open("../../text/content.txt","r")
txtstr = f.read() #将txt文件的所有内容读入到字符串txtstr中
f.close()
chatbot = ChatBot("小土豆",
trainer='chatterbot.trainers.ListTrainer',
read_only=True,
logic_adapters=[
{
"import_path": 'chatterbot.logic.BestMatch'#回话逻辑
},
{
'import_path': 'chatterbot.logic.LowConfidenceAdapter',#回话逻辑
'threshold': 0.65,#低于置信度,则默认回答
'default_response': '我还是个小孩子,不知道怎么回答'
}]
)
conversation = [
"你好",
"Hi~",
"你好啊!"
]
chatbot.train(conversation)
conversation = [
"你好吗?",
"我很好,谢谢!"
]
chatbot.train(conversation)
conversation = [
"你叫什么名字?",
"我叫小土豆"
]
chatbot.train(conversation)
conversation = [
"你过得怎么样?",
"我很好,谢谢!"
]
chatbot.train(conversation)
conversation = [
"哈哈",
"呵呵",
"呵呵哒"
]
chatbot.train(conversation)
response = chatbot.get_response(str(txtstr))
print(response)
f = open("../../text/Reply.txt","w") #设置文件对象
f.write(str(response))
except Exception as e:
g.msgbox("错误:"+str(e))
就是一个chatbot聊天机器人,从content.txt读取用户的话,把结果读到Reply.txt
@Ctrl+c_Ctrl+v程序员: 终端打印的所有错误发一下
@小小咸鱼YwY:
自己解决了,把.pyw改成.py即可
这种错误,设个断点就知道原因了