【发布时间】:2016-05-02 02:41:00
【问题描述】:
我在一个非常早期的简单聊天机器人原型上遇到了问题,该机器人将使用必须添加到响应数据库中的对话,以便以后使用。
import sys,time,random, os.path
typing_speed = 50 #wpm
def slow_type(t):
for l in t:
sys.stdout.write(l)
sys.stdout.flush()
time.sleep(random.random()*10.0/typing_speed)
print ''
slow_type("Hello! My name is TUTAI, or Turing Test Artificial Intelligance")
slow_type("Currently I am in training, so my features arent fully complete.")
slow_type("If you say something I don't understand yet, I will repeat it back to you in order for me to learn and build a databace of responces!")
talk = raw_input()
talk = talk + ".txt"
existance = True
try:
talk = open(talk, "r")
except:
existance = False
talk.close()
if existance == True:
talkBack = open(talk, "r")
print talkBack.read()
但是,当我运行程序时,我得到了这个响应(是的,我检查了文件是否存在)。
Hello! My name is TUTAI, or Turing Test Artificial Intelligence
Currently I am in training, so my features aren't fully complete.
If you say something I don't understand yet, I will repeat it back to you in order for me to learn and build a database of responses!
(I type)Hello
Traceback (most recent call last):
File "H:\TUTAI\firstPythonScript.py", line 31, in <module>
talkBack = open(talk, "r")
TypeError: coercing to Unicode: need string or buffer, file found
谢谢! (我知道我进口了一堆我不需要的东西。请不要提及。)
【问题讨论】:
-
你解决了吗?如果我的回答有帮助,我们将不胜感激。
标签: python python-2.7 artificial-intelligence typeerror chatbot