0

I expect I'm doing something wrong here, but whenever I try to insert the snippet to save session information for the chatbot, the terminal closes immediately with an error. Here's my source:

import aiml
k = aiml.Kernel()
#k.learn("std-startup.xml")
#k.respond("load aiml b")
#k.saveBrain("test.brn")
k.loadBrain("test.brn")
#while True: print k.respond(raw_input("> "))
keepAlive = True
while True: 
    output = k.respond(raw_input("> "))
    print output,
    session = k.getSessionData("Bob")
    sessionFile = file("Bob.ses", "wb")
    marshal.dump(session, sessionFile)
    sessionFile.close()  

new error

Often Right
  • 427
  • 1
  • 9
  • 22

2 Answers2

1

probably you need to use k in place of Kernel

session = k.getSessionData("Bob")
furas
  • 134,197
  • 12
  • 106
  • 148
  • In place of `session = Kernel.getSessionData("Bob")`. But I'm only guessing that you need `aiml.` – furas Jun 29 '14 at 23:13
  • I'm getting an NameError saying 'marshal' is not defined (which it's not; I'm just going by the example on the site) – Often Right Jun 29 '14 at 23:43
  • Okay works fine now, but doesn't save the session data (because I just close the terminal to exit the program which, I'm guessing, doesn't give it the chance to save the session. Should I move the comma to the very end of the loop? Or perhaps make it so when I enter something like 'exit', it ends the loop and saves the file then closes the terminal? – Often Right Jun 29 '14 at 23:48
  • What comma do you mean ? – furas Jun 29 '14 at 23:53
  • The one after 'print output' – Often Right Jun 29 '14 at 23:54
  • You can't move it but I think you don't need it . You can delete comma. – furas Jun 29 '14 at 23:59
  • The problem is that the session gets lost (sort of defeating the purpose of it) – Often Right Jun 30 '14 at 00:01
  • Why ? What do you mean ? What did you expect ? – furas Jun 30 '14 at 00:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/56497/discussion-between-n-soong-and-furas). – Often Right Jun 30 '14 at 00:15
0
print bot.respond(raw_input(">"), "Bob")
ProgramFOX
  • 6,131
  • 11
  • 45
  • 51
Solved
  • 1