4

I'm in need of a flexible framework and would like to try to inject some code in different places of it just to change behavior on the fly.

Since it's a Java project and basically I'm limited to interfaces and playing with the implementations behind those I thought I might give Jython a run and see what that might bring to the table.

I mean, eval() is a powerful function and I could add code as string and have it evaluated, at least in Python and there popped the question since it basically compiles to Java...

What limitations are there for Jython as compared to Python? What can I do in Python that I can't do in Jython?

2
  • 7
    With Jython you lose the ability to use many packages in the cpython ecosystem, but you gain access to the Java ecosystem. Since you already know Java, that may be an acceptable tradeoff. For more see the Jython FAQ, especially Is Jython the same language as Python? Commented Oct 23, 2012 at 17:13
  • For instance Python can use getpass module where as Jython cannot. Commented Oct 24, 2012 at 13:17

2 Answers 2

4

As a previous post noted, you are really looking to compare CPython with Jython. As previously noted, the stable version of Jython is at 2.5.3 with an alpha version for 2.7. This means there are certain features missing from Jython. As an example, ordered dictionaries, counters, and named tuples were all added to the Collections package since 2.5. With Jython you cannot use many 3rd party Python libraries such as NumPy, SciPy, GeoDjango, Lxml, or anything that uses C extensions.

On the other hand, Jython has a few benefits you cannot find using CPython. With Jython you can deploy Django on a standard Java server (e.g. Tomcat, WebLogic, etc...). You can call existing Java classes from Jython code.

Sign up to request clarification or add additional context in comments.

1 Comment

Didn't know about the Django deployment. Thanks!
1

Think of comparing jython with cpython as they are both python but one implemented in c and the other in Java. So with cpython the startup time is much faster. If you check out the startup time for each to execute a hello world example cpython executed the code about 50x faster. Jython stable is currently using Python 2.5 which is far older then the current python 2.7 in the 2 series, and they don't have an implementation of python3. So you would miss out on some of the features there.

$ time jython -c "print 'hello'"
hello
real    0m1.641s
$ time python -c "print 'hello'"
hello
real    0m0.026s

3 Comments

I put what I knew, I recommend post an answer that discusses the difference in more depth.
@delnan -- Is that really true? This answer and the excellent comment by StevenRumbalski on the original post seem to cover it pretty well as far as I'm concerned ... Python can do anything that was added in versions 2.6,2.7,3.0,...3.3 whereas Jython can't. Python is also faster in startup and can use c-extensions. What else (major) is there? -- the minor stuff like garbage collection are unlikely to be of interest to someone asking a question like this I would think ...
@mgilson When I made that comment, the answer was limited to "50x faster startup". It's know slightly better. I consider StevenRumbalski's comment very important too, but this answer does not contain any of it, and I'm talking about this answer alone. Also, those differences are the ones I know despite never researching, let alone using it -- I suspect there are more differences.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.