Hi,
I've a problem that i didn't understand . I'm trying to learn my robot to count; If i ask him "compute 2+3" he say "5", but if i ask him to compute 2 X 5, he can't, of course, he wait for 2*5 instead of 2X5 .
So this is my function in python :
def math(text): print type(text) if isinstance(text, basestring): text.lower() print "string" text.replace('x','*') text = eval(text) print text
for "2+3" math() recept automaticly "5" , python apply eval() automaticly when it receive a message from programAB ?
for "2 x 5 " , i get this error :
SyntaxError: ("no viable alternative at input 'x'", ('<string>', 1, 7, 'math(2 x 5)\n'))
This error appear before execute the first line in the function . I tryed this to get the type of data received to be sure it's a string, but it dosen't worked :(
if someone have an idea ! :D
This is the category used in my .aiml file :
<category><pattern>COMPUTE *</pattern> <template> <oob> <mrl> <service>python</service> <method>exec</method> <param>math(<star/>)</param> </mrl> </oob> </template> </category>
Thx for your help
Try this
Thx Mats, I didn't saw, i
Thx Mats, I didn't saw, i forgot 2 time "test = " ... But the problem is still here.
The error occur when the function is called .(only with "2 x 5", not with "2 + 5" or 2 - 5" or "2 / 5"
Hi ! this is working for me
Hi ! this is working for me (quotes in the aiml ) :
<param>math('<star/>')</param>
yes, that work !! thx
yes, that work !! thx