python写入txt报错_python写txt的时候报错

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

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页