1   Notes On Jython

author:Thava Alagu thavamuni@gmail.com
Date:2016 October 07

1.1   Overview

Jython combines the power of Python’s ease of programming with Java’s rich library implementation. It follow’s Python’s syntax where Java library API is available.

What Does Jython Do Well?

Java investigation
    >>> from java.util import Date
    >>> d = Date()
    >>> print d
    Sat Jan 08 16:26:16 CST 2005
    >>> from java.util import Random
    >>> print dir(Random)
    ['__init__', 'nextBoolean', 'nextBytes', 'nextDouble', 'nextFloat',
    'nextGaussian', 'nextInt', 'nextLong', 'seed', 'setSeed']

Making bean properties accessible
    >>> print Date().time

Glues together libraries already written in Java
Excellent embedded scripting language

Differences - Python & Jython

Python                                   Jython

Multi-platform                           100% Java
Compiles to .pyc                         Any JVM (currently 1.1+)
Extend with C                            Compiles to .class
GIL                                      Extend with Java
Python Garbage Collection                Truly multi-threaded
                                         Java garbage collection

1.2   Controlling Module Search Path

The sys module contains the path object which specifies the list of module search directories. To examine it’s value, we must import the sys module first:

>> import sys
>> from pprint import pprint
>> pprint(sys.path)


The module search path (i.e. sys.path) includes certain platform dependent default directories. In addition, you can control the search path by one of the following methods:

  • Set JYTHONPATH environment variable to include additional directories. They will be prefixed into your module search path. (PYTHONPATH for cpython)

  • The program can dynamically modify the module search path. It can do the following first:

    >>> import sys
    >>> sys.path.insert(0, '/path/to/my/module')
  • If you are running virtualenv, then you can choose to place your module in the local site-packages directory without affecting other installations.

Table Of Contents

Previous topic

Notes On Node.JS

Next topic

1   Linked in Capabilities

This Page