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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值