logo       

Re: Evals from Java: msg#00029

lang.jython.user

Subject: Re: Evals from Java

Jake Eakle wrote:
Hi all,
I know nothing whatsoever about Python. I just downloaded Jython oin the recommendation of someone in some forum responding to a question about how to evaluate strings from Java - it turns out that the standaard libraries provide no real way to do this.

I have a very simple situation - I have a string with a basic mathmatical expression, like "3+45*2" and I want to store it's value in an int from a Java program.

This example shows how to do what you want:
http://www.jython.org/docs/embedding.html

I'm not sure but I think the returned PyObject will actually be a PyInteger and you can call getValue() on it to get the result.

You should know that eval() is a security hole that leaves you open to denial-of-service attacks and probably data loss. Don't eval() strings from an untrusted source.

Kent



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise