|
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 |