[Edu-sig] looking for help with Jython...

luby liao liao@holycow.sandiego.edu
Tue, 29 Apr 2003 21:52:15 -0700


Jeffrey, try this:

1. change first line to

  public class Vehicle {

2. shell> javac Vehicle.java

3. shell> jython

[liao@zen tmp]$ jython
Jython 2.1 on java1.3.1 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import Vehicle
>>> v = Vehicle(3,5,6)
>>> v
Vehicle@3f1179
>>>

cheers, Luby



> I'm in the middle of learning some Java to get ready for next year's
AP
> CSC course.  I would like to make good use of the Python my students
> already know, and I was thinking that Jython might offer some
> interesting educational opportunities.
> 
> What I would most like to be able to do is to import Java classes
into
> Python in order to be able to "play around" with them in the
> interpreter.  So far, I have not been able to make this work.  I'm
> starting with a simple example from our book:
> 
> 
> class Vehicle {
>     public int passengers;
>     public int fuelcap;
>     public int mpg;
>
           
>     public Vehicle(int p, int f, int m) {
>         passengers = p;
>         fuelcap = f;
>         mpg = m;
>     }
>
           
>     public int range() {
>         return mpg * fuelcap;
>     }
>
           
>     public double fuelneeded(int miles) {
>         return (double) miles / mpg;
>     }
> }
> 
> (Actually, I added all the "public"s because otherwise Jython
couldn't
> see them when I did:
> 
> import Vehicle
> 
> How can I create a Vehicle object inside of Jython?
> 
> Thanks!
>