Re: Integration with java (Jpype vs. JPE)
Cameron Laird wrote: In article <[EMAIL PROTECTED]>, Jon Perez <[EMAIL PROTECTED]> wrote: Can someone summarize in a nutshell what is the difference between JPype and JPE? JPE's the original. It provided more functionality than JPype has achieved so far, I believe (though that could change any day). I think no one now maintains JPE. Someone really ought to include a couple of sentences to that effect on the front page of http://jpype.sf.net/ >. Well, Cameron summed it up pretty good :) I'd add that The only major (and yes I know it is VERY major) funtionailty missing in JPype is the ability to subclass Java classes in Python. On the other hand JPype will (soon) have functionality that JPE doesnt have. Java arrays can already (in 0.4) be iterated as regular Python collections. Version 0.5 will add that same behavior for Java collections (Map, List, Set, Iterator). Of course, the above is based on the JPE documentation, because I havent been able to get JPE to work. About Cameron's suggestion, sure. I'll do it as soon as I (or someone else) can get both JPype and JPE to work so they can be compared through more than just their respective documentation. Steve a.k.a devilwolf on sourceforge -- http://mail.python.org/mailman/listinfo/python-list
Re: Integration with java (Jpype vs. JPE)
Istvan Albert wrote: Cameron Laird wrote: Someone really ought to include a couple of sentences to that effect on the front page of http://jpype.sf.net/ >. Now I remember visiting this site, but never understood how it actually worked. Examples such as: from jpype import * startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea") java.lang.System.out.println("hello world") shutdownJVM() in three different versions are the only code examples that to show "complete" working snippets. I'm still clueless as to how would one say share a list between python and java. Istvan. I am sorry you find the site so confusing ... perhpas I shold post a more complete example in a prominent location ... To asnwer your question more fully, the jpype-specific cide is only for looking up the Classes and startting/stopping the environment. For everything else, Java objects and classes are used as regular Python objects. In version 0.4.x, the API mostly remain Java's. This means some of the basic magic python methods have been mapped to java equivalent (like __str__ mapped to toString() and __eq__ mapped to equals()). If you have any questions, feel free to post them on the feedback list on sourceforge. I check it every day and I try to answer as quickly as possible. Steve, aka devilwolf on sourceforge, maintainer of JPype -- http://mail.python.org/mailman/listinfo/python-list
Re: Integration with java (Jpype vs. JPE)
Istvan Albert wrote: Steve Menard wrote: To asnwer your question more fully, the jpype-specific cide is only for looking up the Classes and startting/stopping the environment. For everything else, Java objects and classes are used as regular Python objects. Thanks for the response. Currently I don't need to use java but in the past when I explored such a possibility I looked at jpype and I was unable to understand from the documentation what it actually does. There is a lot of text there, but it is all concerning catching errors or other subtleties. For a new visitor the most important question is about how it works, what does it do, and how can it be applied for the given problem. > everything else, Java objects and classes are used as regular Python > objects. This is too generic. My question was a little more specific, how would I pass a python list as an argument of a java class/method or transform a java list into a python one? You don't have to answer it here, I'm just pointing out the kind of questions that I was unable to get an answer for on the jpype website. best, Istvan. I see what you mean. And I agree fully. I guess that's one more thing to put on the TODO list hehe. Thanks for the input. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: embedding jython in CPython...
Jim Hargrave wrote: I've read that it is possible to compile jython to native code using GCJ. PyLucene uses this approach, they then use SWIG to create a Python wrapper around the natively compiled (java) Lucene. Has this been done before for with jython? Another approach would be to use JPype to call the jython jar directly. My goal is to be able to script Java code using Jython - but with the twist of using Cpython as a glue layer. This would allow mixing of Java and non-Java resources - but stil do it all in Python (Jython and Cpython). I'd appreciate any pointers to this topic and pros/cons of the various methods. Well now that IS getting kinda complicated ... AS far a natively compiling Jython scripts ... well, if you natively compile them, it'll hard to "script" you java code afterward (I assume by scripting you mean loading scripts at runtime that were not know at compile time). As for using JPype ... well it depends on what you want to script. if you Java code is the main app, I'd eschew CPython completely and use Jython to script. If you main app is in Python, and the Java code is "simply" libraries you wish to use, then I'f go with CPython + Jpype. It is very easy to manipulate Java objects that way, even to receive callbacks. I guess it all comes down to what you mean by scripting, and exaclt what the structure of your application (as far as what is java and non-java). If you care to explain your situation a bit more, we'll be better able to help you. Steve Menard Maintainer of http://jpype.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
JPype and classpath (Was Re: embedding jython in CPython... )
While we are on topic, I am having some trouble understanding JPype classpath. How do I init the JVM with the folder in which the Python program is located included in the classpath? I tried t = JPackage('.').test That did not work. My environment variable includes current folder in the classpath I tried passing it as an argument to startJVM. Didn't help. I think my main use is going to be using CPython with a few Java custom classes and if anyone has a snippet on this it would really help me. Thanks That's easy. First realise that "." denotes the current working directory, not the "directory where the python program is located". Second, JPackage uses Java package names. So, assuming you java classes are properly stord in a directory called "classes" at the same level as your python script (see how java looks up classes on the filesystem for what "properly" means), here is a snippet that will do what you wanted : #== import os, os.path, jpype root = os.path.abspath(os.path.dirname(__file__)) jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s%sclasses" % (root, os.sep)) #== Or alternately, if the Java classes you want to use ar in JAR files, in a lib directory at the same level as your python script : #== import os, os.path, jpype root = os.path.abspath(os.path.dirname(__file__)) jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s%slib" % (root, os.sep)) #== The magic in the above script is the __file__ variable, which stores the absolute path to the currently executing Python script. If you have both situation (you classes in the classes directory and some JARS containing stuff that they uses) you can combine the above : #== import os, os.path, jpype root = os.path.abspath(os.path.dirname(__file__)) jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s%sclasses" % (root, os.sep), "-Djava.ext.dirs=%s%slib" % (root, os.sep)) #== Hopefully this will help. -- Steve Menard Maintainer of http://jpype.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: embedding jython in CPython...
Jim Hargrave wrote: Sorry - should have given more detail. That's what I get for posting at 1:00AM. What I want to do us write scripts in CPython that access Windows ActiveX such as Word and IE. Obviously Jython can't do this (easily at least). I also have Jython scripts that provide a high level layer on top of various Java libraries. I'd like to write as much code in Python as possible. But I have a mixture of incompatible CPython and Jython scripts - that's why I would like to embed Jython in CPython. If I can call my Jython scripts from CPython I can have the best of both world's! Would I be able to embed Jython using JPype? The PyLucene approach (compile Java source with GCJ then wrap with SWIG) looks interesting - but complicated. Here's an example of embedding Jython in a regular Java app: http://www.jython.org/docs/embedding.html Imagine doing the same in CPython, but with JPype or GCJ/SWIG. Certainly! As far as JPype is concerned though, Jython is just another library. What I mean is, the API to lauch your Jython scripts will be identical JPype as though coded in Java. There will be no "magic" to bridge CPython and Jython. The obvious advantage of going that way though, instead of the GCJ approach, is that you keep the full dynamicity of Jython. I am curious to know what makes your Jython code incompatible with CPython. If it is only because it uses Java classes, it might not be too difficult to port them to CPython+Jpype. Let me know if you need any help. -- Steve Menard Maintainer of http://jpype.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Help on project, anyone?
Georg Brandl wrote: Hello, to train my Python skills I am looking for some project I can contribute to. I learned Python about one year ago, and had already some programming background behind (I contributed to SharpDevelop for instance), so I'm not the complete newbie. About myself: I'm a 20 year old German with strong interests in programming and, of course, especially in Python (I love it...). Does anyone run, or participate in, a project looking for fellow programmers? I don't have a special area of interest, well, perhaps web programming... Thanks, Georg You know what I would do? I would go on Sourceforge. Try to find a project that seems interestingto you. and then contact the Maintainer see if you can help. Many project also advertise the kind of help they need. -- Steve Menard Maintainer of http://jpype.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: JPype and classpath (Was Re: embedding jython in CPython... )
[EMAIL PROTECTED] wrote: Thanks for the response. However, I continue to have problems. Allow me to give some more detail. For simplicity of testing, I hard coded the classpath and JVM path (BTW getDefaultJVMPath() returns None on my system) import os, os.path from jpype import * startJVM("C:/jdk1.5.0/jre/bin/client/jvm.dll", "-Djava.class.path=D:/Temp/classes") ... shutdownJVM() I have setup a classes folder in the script folder (D:/Temp) and have placed test.class in it. I run the script from the script folder (working directory is the same as script's root path in this case) Now how do I load the class test? I am afraid I cannot make that out from the docs. The simple test class is public class test { public int i = 100; } What do I have to do before I can write test().i ? Thank you for your time. About the getDefaultJVMPath(), could you send me your system information? On windows, JPype uses the contents of the registry to find the JVM. Of course, the usefulness of this mechanism is limited byt he sample of configurations i can test (I have only one machine). So any info you can provide me on yours can only help. About the classpath. JPype 0.4 currently cannot import classes that are in the "default" package. The fix is easy, simply put your "test" class in a package. For exmaple, if you put the class in the package "test", the code to load it would be : test = jpype.JPackage("test").test -- Steve Menard Maintainer of http://jpype.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: JEP and JPype in a single process
skn wrote: > Hello, > > I have written a very simple java class file, which invokes a Python script > using JEP. > > Code snippet:- > --- > Jep jep = new Jep(false); > jep.runScript("C:\\temp\\testscript.py"); > jep.close(); > > Now inside this Python script I want to make Java calls using JPype. > If I use startjvm() inside this Python script, a Runtime Error (exception) > is thrown. > Also tried attachThreadToJVM(), but doesn't work, again Runtime Error. > > Any clues as to how I could achieve my goal?? > The interaction shown below should happen in a single process. > > JAVA ==> jep ==> PYTHON ==> jpype ==> JAVA > > Regards, > skn > > You're trying to do something I hope to make possible somewhere down the road ... As of today, I do not think it is possible. JPype does not provide a way to initialize the JVM-bridge system except for startJvm .. which seems to be prohibited when a JVM is already running. AttachThreadToJVM will only work once the JVM-bridge system has been initialize. I will look into providing a sister method to startJVM to attach to the currently running JVM instead of starting a new one. IF it does not require major changes I will release it as 0.5.1. If you'd like you can submit an enhancement request on the JPype sourceforge page, so this doesn't get lost. -- Steve Menard Maintainer of http://jpype.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: JEP and JPype in a single process
Steve Menard wrote: > skn wrote: > >> Hello, >> >> I have written a very simple java class file, which invokes a Python >> script >> using JEP. >> >> Code snippet:- >> --- >> Jep jep = new Jep(false); >> jep.runScript("C:\\temp\\testscript.py"); >> jep.close(); >> >> Now inside this Python script I want to make Java calls using JPype. >> If I use startjvm() inside this Python script, a Runtime Error >> (exception) >> is thrown. >> Also tried attachThreadToJVM(), but doesn't work, again Runtime Error. >> >> Any clues as to how I could achieve my goal?? >> The interaction shown below should happen in a single process. >> >> JAVA ==> jep ==> PYTHON ==> jpype ==> JAVA >> >> Regards, >> skn >> >> > > You're trying to do something I hope to make possible somewhere down the > road ... > > As of today, I do not think it is possible. JPype does not provide a way > to initialize the JVM-bridge system except for startJvm .. which seems > to be prohibited when a JVM is already running. > > AttachThreadToJVM will only work once the JVM-bridge system has been > initialize. > > I will look into providing a sister method to startJVM to attach to the > currently running JVM instead of starting a new one. IF it does not > require major changes I will release it as 0.5.1. If you'd like you can > submit an enhancement request on the JPype sourceforge page, so this > doesn't get lost. > > > OK .. it now works. There are a few caveats that cannot be resolved until either JEP and JPype can somehow cooperate or I finish what I started and basically fold the JEP functionality in JPype. I will release the new functionality in as version 0.5.1. The "gotchas" are going to be in a readme-jep.txt file. -- Steve Menard Maintainer of http://jpype.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Communication between JAVA and python
Jacques Daussy wrote: Hello How can I transfert information between a JAVA application and a python script application. I can't use jython because, I must use python interpreter.I think to socket or semaphore, but can I use it on Windows plateform ? thanks a lot jack Well, it all depends on the exact deployment scenario you;re facing. If you're java program can be embedded dinside hte python scripts, then JPype (see my sig at the bottom of this post) can certainly help you. Otherwise ... Is there a java way to "access" you java program from outside it's process? I mean things like RMI servers, or EJBs. If so, again JPype can take the place of a "java" client. If not, there is no magic. You must first find a way to contact you Java process. If that remote-call technology is "standard", i.e. Something like SOAP or XML-RPC, then you can find a python technology to access it. If its not standard, but tehre is a Java way to use it, Again jpype can be your friend. If you can tell us more about the nature of each program (Python and Java) we may be better able to help you. -- Steve Menard Maintainer of http://jpype.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Mixing metaclasses and exceptions
In writing the next version of Jpype (Python to Java bridge), I have hot a rather unpleasant wall ... Hopefully it is I who is doing something wrong and i can be fixed ... Since I am bridging Java classes and presenting them as Python classes, I decided to try to create a corresponding python class for every Jva classes accessed inside the python program. So far, everything is great .. until we get to exception handling. Since I am creating classes, on the fly, I thought the easiest and most pythonic way to do it would be to create a metaclass. This is true also for the Java exception classes. The problem arises when I try to raise one of those exception classes ... it sems Python will not allow classes that have a custom metaclass to be raised as exceptions! Even though those classes derive from Exception! To illustrate, try the following snippet : class mc(type) : pass class foo(Exception, object) : __metaclass__ = mc pass try : raise foo, 'ex' except Exception, ex : print ex.__class__, ex Note the above code has nothing to do with JPype. When I try to run the above, I get the following error : exceptions.TypeError exceptions must be classes, instances, or strings (deprecated), not mc Is there anything I can do to raise exception that have metaclasses? Maybe I can make my metaclass acceptable to "raise" somehow? Thanks for any help anyone can provide. Steve -- http://mail.python.org/mailman/listinfo/python-list
Metaprogramming question
I have a need to create class instance without invokking the class' __init__ method. Were I using old-style classes, I'd use new.instance() function. However, I am using new-style classes and new.instance() complain "TypeError: instance() argument 1 must be classobj, not type" ... So my question is, how to replicate new.instance() functionality with new classes? Steve Menard Author and Maintainer of http://jpype.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: (semi-troll): Is Jython development dead?
"Walter S. Leipold" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > John Roth ([EMAIL PROTECTED]) wrote: >> I've had a couple of inquiries about Jython support >> in PyFIT, and I've had to say that it simply isn't >> supported. The latest point release requires Python >> 2.3, and 2.4 will be required in the next year or so. >> >> John Roth >> Python FIT > > Just last month, Sun hired Charles Nutter and Thomas Enebo to work on > JRuby > full-time. Can somebody with some street cred (like the PSF) do something > to persuade Sun to support Jython the same way? > > -- Walt Keep in mind that Ruby and Python are close enough in style, that any improvements those guys make will also benifit Jython. Also, they haven't been hired to work exclusively on JRuby. They were also hired to look at tools to help with programming with dynamic languages. In this regard, they can help not only Jython, but Python itself! All in all a very good thing to see a high-profile company invest in dynamic languages. Steve Menard -- http://mail.python.org/mailman/listinfo/python-list
PEP proposal : Getting rid of the extension version/compiler dependency
It's been observed a couple times recently ... distributing and compiling extensions is a pain, especially on windows, when the main supported compilers are not freely availble .. nor even commercially availble anymore. What we need is a way to break out of this dependency. A way for python extensions to be built using any C compiler and be able to target multiple Python runtime version with a single binary build. I believe I have such a solution.It is heavily influenced byt Java's Native Interface, which achieved this independence since day one. The technical details are too combersome to post here, so I added a page to my projects's homepage detailing my proposal. If there is interest, I'd be interested in working on the PEP and the implementation.The URL for the proposal is http://jpype.sourceforge.net/pni.html This solution may not be complete. Of multi-platform details might make some suggestion impossible or impractical. Please take this proposal as a starting point for a discussion. I have a working prototype for steps 1 that I am using to implement JPype. So this is not a pipe dream. it is real and functional. Please leave tour comments here, or better yet on my blog at http://jpype.blogspot.com . Steve Menard Author and Maintainer of JPype ( http://jpype.sourceforge.net ) -- http://mail.python.org/mailman/listinfo/python-list