|
From: brian z. <bz...@zi...> - 2001-03-02 13:07:13
|
> hi..im trying to call the PythonInterpreter() from within a java app, and
> run a python program.Since Python does not have *native* support for
> interfaces, what can I do after importing a java interface? Also,when I
After importing an interface, you can build a class implementing it as if it
was a class.
class myclass(someinterface):
def callme(self, somearg):
pass
> import code from java that does use interfaces(for e.g. Vector implements
> List,Map etc),the following code
> from java.util import Vector
> sim=Vector
> sim.addElement("first.py")
> throws an error TypeError: addElement(): expected 2 args; got 1
The reason you get the exception is because you are attempting to invoke the
method on the class Vector, rather than an instance of the class Vector.
You can fix this by:
>>> from java.util import Vector
>>> sim = Vector()
>>> sim.addElement("first.py")
My guess is it's not that an object implements an interface but that you are
not creating instances of classes. In Java parlance, calling addElement as
you did above would work if addElement() was a static method.
>
> so what do I typecast the first argument to?
> sim.addElement(Vector,"fist")
> gives TypeError: addElement(): self arg can't be coerced to (well, it
> doesnt say what...)
>
The self arg is automatically passed to the method when a method is invoked
on an instance, not the class.
brian
|