programAB -> Python data type ...

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

Mats's picture

Try this


def math(text):
	print type(text)
	if isinstance(text, basestring):
		text = text.lower()
		print "string"
		text = text.replace('x','*')
		text = eval(text)
	print text
beetlejuice's picture

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"

SyntaxError: ("no viable alternative at input 'x'", ('<string>', 1, 7, 'math(2 x 5)\n'))

    at org.python.core.ParserFacade.fixParseError(ParserFacade.java:95)
    at org.python.core.ParserFacade.parse(ParserFacade.java:205)
    at org.python.core.Py.compile_flags(Py.java:1976)
    at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:267)
    at org.myrobotlab.service.Python$PIThread.run(Python.java:180)
------
[python.interpreter.16] [ERROR] python error Python error - ------SyntaxError: (no viable alternativ
moz4r's picture

Hi ! this is working for me

Hi ! this is working for me (quotes in the  aiml ) :

<param>math('<star/>')</param>

 

 

beetlejuice's picture

yes, that work !! thx

yes, that work !! thx