TWiki> Public Web>JythonUpgrade (revision 2)EditAttach

Upgrade to Jython 2.5


Up to HIPE 7, we have been using the Jython 2.1 library, which mostly uses the syntax of Python 2.1
Starting from HIPE 8 we will upgrade to Jython 2.5, which uses the same syntax rules as Python 2.5.

In most cases, your scripts will run fine; however, in certain cases you may need to adapt them. This page lists the known differences between Jython 2.1 and Jython 2.5

Wrong locations of global import statements

You may have written code where global import statements are done within a Jython function. As of Jython 2.5, this is not allowed anymore (in fact, it was not allowed in Python 2.1 but Jython 2.1 inadvertently allowed for it).

When executing the code against Jython 2.5, you will get messages such as:

SyntaxWarning: import * only allowed at module level

To fix your code, you have two options:

  • Move the global import statement out of the function and to the top of your script.
  • Make the import statement specific.

See below for examples of fixes to incorrect code.

Current: wrong use of global import

:
def foo():
    from herschel.ia.foo.banana import * # global import statement, to access SomeThing
    x=SomeThing()
    return

Fix 1: global import statement at start of script

from herschel.ia.foo.banana import *
:
def foo():
    x=SomeThing()
    return

Fix 2: make import statement specific

Alternatively, you can make the import statement specific:

:
def foo():
    from herschel.ia.foo.banana import SomeThing
    x=SomeThing()
    return

Known jython module changes

Jython 2.1 Jython 2.5
import javaos import os

Edit | Attach | Watch | Print version | History: r10 | r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r2 - 2011-05-02 - JorgoBakker
 
This site is powered by the TWiki collaboration platform Powered by Perl