後で使用できる応答のデータベースに追加する必要がある会話を使用する単純なチャット ボットの非常に初期のプロトタイプに問題があります。
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
ありがとう!(必要のないものをたくさんインポートしたことは知っています。それについては言及しないでください。)