|
Re: Evals from Java: msg#00037lang.jython.user
In Jython 2.2 the return value is a PyObject because it can either be a PyInteger or a PyLong (This is a post 2.1 feature in CPython -- ints auto-convert to longs on overflow) If you are sure that you will stay in the integer range you can cast to a PyInteger and call getValue(). If you might overflow, you'll want to check to see if you have a PyLong and then cast to PyLong (then you can call getValue() from PyLong, which will yield a BigInteger. -Frank On 3/25/06, Jake Eakle <jseakle@xxxxxxxxx> wrote: > Thanks everyone for your help! I finally got it up and running, and it > worked splendidly. You may be interested in knowing, Kent, that the returned > PyObject is not in fact a PyInt - I worked around this by calling toString > on it and then using Integer.parseInt. I'm sure there's a better way, but it > worked fine. Again, thanks much! > > Jake > > > On 3/25/06, Jeff Emanuel < jemanuel@xxxxxxxx> wrote: > > jython.jar must be in your compile classpath. > > > > Jake Eakle wrote: > > > Thanks! The code is all set up now, but I am still having a bit of a > problem > > > - it can't find org.python.core or > org.python.util.PythonInterpreter. I'm > > > compiling using javac in a Mac OS X terminal, and both the java files > and > > > the jythonRelease_2_2alpha1 folder are both in the home directory. I > tried > > > compiling the example you pointed me to, from its default position in > the > > > Jython file heirarchy, and it gave the same errors. I installed Jython > > > fully, etc. and I'm not sure how to proceed. Help would be much > appreciated. > > > > > > > > > > > > On 3/24/06, Kent Johnson <kent37@xxxxxxx> wrote: > > > > > >>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 > > >>_______________________________________________ > > >>Jython-users mailing list > > >>Jython-users@xxxxxxxxxxxxxxxxxxxxx > > >> > https://lists.sourceforge.net/lists/listinfo/jython-users > > >> > > > > > > > > > > ------------------------------------------------------- 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&kid0944&bid$1720&dat1642
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Where do we go from here to get to 2.2 "proper" ?, Ray Djajadinata |
|---|---|
| Next by Date: | Re: Where do we go from here to get to 2.2 "proper" ?, Paul D. Fernhout |
| Previous by Thread: | Re: Evals from Java, Jake Eakle |
| Next by Thread: | JFreeChart in jython AttributeError: no attribute 'JFreeChart, Øystein Lekang |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |