views:

312

answers:

5

So you aren't allowed to use Jython for the production code you develop at work. You can, instead, use it to help you on your daily tasks and activities writing that Java code. The question is: How do you use Jython and how did that help your development and/or productivity?

+3  A: 

I run a Jython command line, and dynamically create/interrogate my classes on the command line. I find that very effective for determining how classes will respond to various inputs (usually these get coded up into tests and the like).

I also found this very useful for learning Swing - dynamically resizing/repacking and adding/removing components.

You can do the same with other Java scripting languages (e.g. BeanShell) but Jython's the one I picked up on and used first.

Brian Agnew
Selected as the accepted answer because it seemed the most interesting and relevant to me.
Andrei Vajna II
+1  A: 

I use litte scripts to run ant-scripts starting and stopping jboss ... the scripts run everywhere win and linux (no need for special .bat /.sh)

as an example my little util.py (to import)

import sys
import os
import shutil

def ant(buildfile,target=''):
    antrun = os.sep.join([os.environ['ANT_HOME'],'bin','ant'])
    action = ' '.join([antrun,'-buildfile',buildfile,target])
    os.system(action)

def jboss_start():
    jbrun = os.sep.join([os.environ['JBOSS_HOME'],'bin','run'])
    action = ' '.join(['start',jbrun,'-c default -b %COMPUTERNAME%'])
    print action
    os.system(action)

def jboss_stop(args='--user=admin --password=admin -s %COMPUTERNAME% -S'):
    os.environ['NOPAUSE'] = "TRUE"
    jbstop = os.sep.join([os.environ['JBOSS_HOME'],'bin','shutdown'])
    action = ' '.join([jbstop,args])
    print action
    os.system(action)

def pjoin(*args):
    rc = os.sep.join(args)
    return os.path.normpath(rc)

def env(key,value=None):
    if value :
        os.environ[key] = value
    return os.environ.get(key,'')

def cp(src,dst):
    shutil.copy(src, dst)

def mkdir(dst,mode=0777):
    if not os.path.exists(dst) :
        os.makedirs(dst, mode)

.. and i run test in eclipse with jython (pydev). jython is perfect to write little tests of your java code.

Blauohr
You should really investigate the subprocess module :-)
Nicholas Riley
Okay Okay os.system is a quick hack :-)
Blauohr
+1  A: 

I use Jython to access a Sybase database using the jconn2.jar and the included com.sybase.jdbc2.jdbc.SybDriver. Together with zxJDBC or iBATIS this allows me to programm in Python against one of the main databases in the company I work for.

A: 

we use jython to run 'jybot', the test runner that is part of the robot framework. It lets us write java code as the glue between our java code and our test scripts.

Bryan Oakley
A: 

Because:

  • I like Python ,
  • and one of our main product is written in Java and uses JDBC drivers

I use Jython with zxJDBC to do some tools like benchmarking queries, testing schema etc. For examaple I created tool to export Oracle database information (tables, columns, triggers, procedures) which can be used with Python+cx_Oracle or Jython+Oracle JDBC driver.

Michał Niklas