From: <lc...@cs...> - 2007-06-12 03:46:14
|
Hello, I need to call a java application from a python program. I see that I =20 can create a jython program which have a similar sintax of a python =20 program, even it has the same file extension. I can either compile it =20 using jythonc into a .class file or run it with the jython executable =20 file (jython file.py). I need to know if there is a way to do the =20 opposite, this means to just execute the Jython program using the =20 python command (from the console, like: python file.py). I tried it =20 but it didn't work I get the following error: C:\jython2.2b2>python listing7.py Traceback (most recent call last): File "listing7.py", line 1, in ? from java.util import Random ImportError: No module named java.util I am trying to run a small example that imports the Random class, but =20 it doesn't recognize it. When I use the jython command there is no =20 problem it executes it well. Please let me know what I am doing wrong =20 and also if there is a way to execute the jython programs using python. Thanks, Lorena Carlo |
From: Jeff E. <jem...@fr...> - 2007-06-12 04:02:54
|
Change p to j c:\jython2.2b2>jython listing7.py lc...@cs... wrote: > Hello, > > I need to call a java application from a python program. I see that I > can create a jython program which have a similar sintax of a python > program, even it has the same file extension. I can either compile it > using jythonc into a .class file or run it with the jython executable > file (jython file.py). I need to know if there is a way to do the > opposite, this means to just execute the Jython program using the > python command (from the console, like: python file.py). I tried it > but it didn't work I get the following error: > > C:\jython2.2b2>python listing7.py > Traceback (most recent call last): > File "listing7.py", line 1, in ? > from java.util import Random > ImportError: No module named java.util > > I am trying to run a small example that imports the Random class, but > it doesn't recognize it. When I use the jython command there is no > problem it executes it well. Please let me know what I am doing wrong > and also if there is a way to execute the jython programs using python. > > Thanks, > > Lorena Carlo > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |
From: <lc...@cs...> - 2007-06-12 04:56:37
|
Hello, Yes, I tried both (p and j, with j works). So my question was, if is =20 it possible to call a jython application using python command, or to =20 create a jython program as python module?. Sorry if this question is =20 too naive for this group, I am a beginner in jython and python. Thanks, Lorena Carlo Quoting Jeff Emanuel <jem...@fr...>: > Change p to j > > c:\jython2.2b2>jython listing7.py > > lc...@cs... wrote: >> Hello, >> >> I need to call a java application from a python program. I see =20 >> that I can create a jython program which have a similar sintax of a =20 >> python program, even it has the same file extension. I can =20 >> either compile it using jythonc into a .class file or run it with =20 >> the jython executable file (jython file.py). I need to know if =20 >> there is a way to do the opposite, this means to just execute the =20 >> Jython program using the python command (from the console, like: =20 >> python file.py). I tried it but it didn't work I get the =20 >> following error: >> >> C:\jython2.2b2>python listing7.py >> Traceback (most recent call last): >> File "listing7.py", line 1, in ? >> from java.util import Random >> ImportError: No module named java.util >> >> I am trying to run a small example that imports the Random class, =20 >> but it doesn't recognize it. When I use the jython command there =20 >> is no problem it executes it well. Please let me know what I am =20 >> doing wrong and also if there is a way to execute the jython =20 >> programs using python. >> >> Thanks, >> >> Lorena Carlo >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by DB2 Express >> Download DB2 Express C - the FREE version of DB2 express and take >> control of your XML. No limits. Just data. Click to get it now. >> http://sourceforge.net/powerbar/db2/ >> _______________________________________________ >> Jython-users mailing list >> Jyt...@li... >> https://lists.sourceforge.net/lists/listinfo/jython-users |
From: David H. <Dav...@sa...> - 2007-06-12 13:15:26
|
Yes, you can create a module that can be run either with Python or = Jython. The trick is to make sure that you only import Python modules = and not Java classes. If you have "from java.anything import ..." then you know it will not = work with Python, because Python cannot import any Java classes. = Instead, for random numbers, try this: import random print random.random() Most of the standard Python 2.2 modules documented here will run in both = Jython and Python: http://www.python.org/doc/2.2.3/modindex.html Hope this helps, David H -----Original Message----- From: jyt...@li... = [mailto:jyt...@li...] On Behalf Of = lc...@cs... Sent: Tuesday, June 12, 2007 12:56 AM To: Jeff Emanuel Cc: jyt...@li... Subject: Re: [Jython-users] How to access a java program from python Hello, Yes, I tried both (p and j, with j works). So my question was, if is it = possible to call a jython application using python command, or to create = a jython program as python module?. Sorry if this question is too naive = for this group, I am a beginner in jython and python. Thanks, Lorena Carlo Quoting Jeff Emanuel <jem...@fr...>: > Change p to j > > c:\jython2.2b2>jython listing7.py > > lc...@cs... wrote: >> Hello, >> >> I need to call a java application from a python program. I see =20 >> that I can create a jython program which have a similar sintax of a =20 >> python program, even it has the same file extension. I can either =20 >> compile it using jythonc into a .class file or run it with the =20 >> jython executable file (jython file.py). I need to know if there is = >> a way to do the opposite, this means to just execute the Jython =20 >> program using the python command (from the console, like: >> python file.py). I tried it but it didn't work I get the following = >> error: >> >> C:\jython2.2b2>python listing7.py >> Traceback (most recent call last): >> File "listing7.py", line 1, in ? >> from java.util import Random >> ImportError: No module named java.util >> >> I am trying to run a small example that imports the Random class, =20 >> but it doesn't recognize it. When I use the jython command there =20 >> is no problem it executes it well. Please let me know what I am =20 >> doing wrong and also if there is a way to execute the jython =20 >> programs using python. >> >> Thanks, >> >> Lorena Carlo >> >> >> --------------------------------------------------------------------- >> ---- This SF.net email is sponsored by DB2 Express Download DB2=20 >> Express C - the FREE version of DB2 express and take control of your=20 >> XML. No limits. Just data. Click to get it now. >> http://sourceforge.net/powerbar/db2/ >> _______________________________________________ >> Jython-users mailing list >> Jyt...@li... >> https://lists.sourceforge.net/lists/listinfo/jython-users -------------------------------------------------------------------------= This SF.net email is sponsored by DB2 Express Download DB2 Express C - = the FREE version of DB2 express and take control of your XML. No limits. = Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |
From: <lc...@cs...> - 2007-06-12 16:21:42
|
Hello, Thanks for the answers. I have a third party java library that I need to use in an application =20 implemented in python. I thought jython could be the alternative, but =20 I am not sure of that now considering the answers I have received. =20 Anybody think there is a a way of doing this with jython?. Otherwise, =20 is there any other alternative?. Thanks, Lorena Quoting "Diez B. Roggisch" <die...@ar...>: > On Tuesday 12 June 2007 06:56, lc...@cs... wrote: >> Hello, >> >> Yes, I tried both (p and j, with j works). So my question was, if is >> it possible to call a jython application using python command, or to >> create a jython program as python module?. Sorry if this question is >> too naive for this group, I am a beginner in jython and python. > > The whole purpose of Jython is to make python code run under the JVM of Ja= va. > > Depending on your code, one script can run both in Jython and in CPython. > > But you can't run code that uses e.g. java.util-classes in CPython. =20 > It doesn't > have them. > > What do you _really_ want - what's your task? > > Diez > |
From: Diez B. R. <de...@we...> - 2007-06-12 17:21:54
|
lc...@cs... schrieb: > Hello, > > Thanks for the answers. > > I have a third party java library that I need to use in an application > implemented in python. I thought jython could be the alternative, but I > am not sure of that now considering the answers I have received. > Anybody think there is a a way of doing this with jython?. Otherwise, > is there any other alternative?. Unless you python app can fully run under Jython - no, Jython won't help. But there are alternatives, e.g. JPype which bridges CPython with java. Diez |
From: <lc...@cs...> - 2007-06-12 19:28:34
|
Diez, many thanks for the information. Cheers, Lorena Quoting "Diez B. Roggisch" <de...@we...>: > lc...@cs... schrieb: >> Hello, >> >> Thanks for the answers. >> >> I have a third party java library that I need to use in an >> application implemented in python. I thought jython could be the >> alternative, but I am not sure of that now considering the answers >> I have received. Anybody think there is a a way of doing this with >> jython?. Otherwise, is there any other alternative?. > > Unless you python app can fully run under Jython - no, Jython won't > help. But there are alternatives, e.g. JPype which bridges CPython with > java. > > Diez |