Home | www.python.org
Download | Documentation

Documentation
Overview
Executive Summary
Invoking Jython
Jython Registry
Embedding
Compiling Jython from source
Working with Java
The Basics
JavaBean Properties
Java arrays
Subclassing
Building applets, servlets, beans...
Reloading java classes
zxJDBC
Python Docs (exits)
Python Tutorial
Library Reference
Other
Jython vs. CPython
Jython FAQ (exit)
List Archives (exit)
JPython paper (exit)
Email Us
jython-dev@lists.sourceforge.net

### Invoking the Jython Interpreter

Jython can be invoked from the shell using the following command:

    jython [options] [-jar jar | -c cmd | file | -] [args]

Options and arguments:

-i | inspect interactively after running script, and force prompts, even if stdin does not appear to be a terminal
-S | don't imply import site on initialization
-Dprop=value | Set the jython property prop to value
-jar jar | program to run is read from the `__run__.py` file in the specified jar file
-c cmd | program to run is passed in as the cmd string. This option terminates the options list
file | run file as the program script
- | program is read from standard-in (default; interactive mode is used if on a tty). This flag allows you to pipe a file into Jython and have it be treated correctly. This would be useful in a case like: `filter file | jython -`
--help | print a usage message and exit
--version | print Jython version number and exit
args | arguments passed to the program in `sys.argv[1:]`

### Details

`jython` is a short script that invokes your local JVM, sets the Java property `install.path` to an appropriate value, and then runs the Java classfile `org.python.util.jython`.

### Making Jython Scripts Executable

To make a jython ".py" file executable on a Unix system you can add the following line to the top of the file:

    #! /usr/bin/env jython

For this magic to work, you must have `jython` somewhere on your standard PATH. You also must also make the ".py" file executable. Typically this is done with the command: `chmod +x foo.py`.

Note: "#! <...>/jython" will probably not work to make your script executable. This is because "jython" is itself a script, and the #! magic requires that the file to execute is a binary executable on most Unix variants. Using "/usr/bin/env" will get around this problem - and make your scripts more portable in the bargain.