[Tutor] python and java report writers

Alan Gauld alan.gauld at btinternet.com
Mon Aug 17 21:33:49 CEST 2009

"John" <jfabiani at yolo.com> wrote

> I'd like to understand how python can integrate with Java in general and 
> then
> how it would work with the Java report writers.  I have read a little 
> about
> jPython but do not understand how to make that work with my python 
> programs.

I assume you mean jython?

jython allows you to take Python code(with af few restrictions) and
compile it into Java so that it can be included in a regukar java program.
Jython also allows you to import java classes into your python code as
if they were python classes - this is how you would use it.

The only snag are those restrictions I mentioned. You need to make
sure your python code does not use any features./modules that are
not supported in Jython.

> It would appear to me it is a way to replace python.

It doesn't replace Python the language but it lets you write Python
code in a Java environment. But you cannot import your Jython code
into CPython and you cannot use any C compiled modules in Jython.

> my python code.  I want to just call a java report writer.  Passing 
> either
> the data or parameters to retrieve the data  and ask it to print a 
> report.  I
> would think that would be straight forward.  But I see nothing about 
> python
> and jasper for example.  Therefore, something is unusual in this case.

Provided you can separate the production of the data from the reporting
then you can use your C Python code to produce the data then write a
Jython module to do the reporting using the Java report writer object.

You just have to run the data producer under CPython and the report
writer under Jython. (Or compile it to run under Java)


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list