As a followup, here's a bit of code that illustrates:
public class MyClass extends SomePyThing
{
public int sum(int val1, int val2)
{
return val1 + val2;
}
}
--jython--
import MyClass
a = MyClass()
a.foo = 2
a.bar = 4
a.sum(a.foo, a.bar)
With a standard Java class, a.foo=2 would fail. With a subclass of
PyInstance, a.foo = 2 would work, but a.sum(...) would fail (AttributeError,
because it can't find the method since reflection isn't used).
Kevin
----- Original Message -----
From: "Kevin Dangoor" <kda...@we...>
To: <jyt...@li...>
Sent: Thursday, July 12, 2001 11:11 AM
Subject: [Jython-users] Making a class that acts as both a Python object and
a Java object
> Jython does a great job emulating Python objects in Java. It also,
> through reflection, does a great job of letting you use Java methods, etc.
> in Jython. It seems like it would be useful to have a base class that
gives
> you both sets of behavior out of the box:
>
> - it would have a __dict__ to store things in
> - it would use reflection to find out about Java methods
> - it would look like a python class and allow you to use Jython's multiple
> inheritance mechanism
>
> This type of thing would allow you to easily build all sorts of extensions
> to Jython. In situations where someone is more comfortable or it is more
> convenient to do something in Java, you can still make objects that look
> like python objects to Jython programs.
>
> I'm just coming back to this after a couple of weeks away, but if memory
> serves subclassing PyObject doesn't give __dict__ or reflection.
Subclassing
> PyInstance does give you a functional __dict__, but doesn't do reflection.
> Subclassing PyClass actually can give both but PyClasses are not quite the
> same. And there are a lot of private and protected members in there which
> prevent easy subclassing.
>
> Has anyone else been interested in such a thing? Any suggestions on an
> approach to take?
>
> Thanks,
> Kevin
>
>
> _______________________________________________
> Jython-users mailing list
> Jyt...@li...
> http://lists.sourceforge.net/lists/listinfo/jython-users
|