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

Jeffrey Elkner jeff@elkner.net
30 Apr 2003 07:51:46 -0400


Thanks, Luby, this worked like a charm!  It is also *way too cool* ;-) 
This is what I had hoped to be able to do, and it worked just liked I
had hoped it would.

We have a real opportunity here to promote Python next year.  I will be
working closely with my colleagues from the other schools in our system
next year to develop the new Java course.  It will be a great chance to
promote the use of Python in our first year courses.  Jython and the
ability to interact with Java classes like this adds tremendously to the
already strong case for using Python.

Thanks again!

jeff

On Wed, 2003-04-30 at 00:52, luby liao wrote:
> 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!
> > 
> 
> 
> _______________________________________________
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig
-- 
Jeffrey Elkner <jeff@elkner.net>