- Can we implement interface directly in Jython? If yes, how (example)?
- Can we embed a Jython script in a way that the script can be called =
several times and keep its environment?
I am looking for examples.
From: Johan Hahn <johahn2003@ho...> - 2004-11-08 21:49:36
You should post these kind of questions to the jython users list. This =
developer list. Since I've already answered them though, I'll post the =
here (just this time).
"Colbert Philippe" wrote:
>- Can we implement interface directly in Jython? If yes, how =
You can't create an interface in Jython that you use as an interface =
defining a class in Java, if that answers your question. You can however =
create pythonic interfaces in Jython (and use them like base classes in =
>- Can we embed a Jython script in a way that the script can be called =
>times and keep its environment?
Why not just save state between invocations to disk? If your state data =
complicated the task can be simplified by using the pickle module.
self.invocations =3D 0
counter =3D pickle.load(open('my.state'))
counter =3D NotSoComplicatedState()
counter.invocations +=3D 1
print 'script called for the %i:th time' % counter.invocations
pickle.dump(counter, open('my.state', 'w'))
From: Kent Johnson <kent37@td...> - 2004-11-09 13:57:36
Colbert Philippe wrote:
> - Can we implement interface directly in Jython? If yes, how (example)?
If you mean, can I write a Jython class that implements a Java
interface? then yes, this is commonly done. Just import the Java
interface and list it as a base class to your class. For example:
from java.awt.event import MouseListener, MouseMotionListener
class TreeMouseListener(MouseListener, MouseMotionListener):
def mousePressed(self, event):
> - Can we embed a Jython script in a way that the script can be called
> several times and keep its environment?
You can preserve the environment yourself between uses. I think that if
you create a PyDictionary and pass it to each interpreter instance they
will all share the same namespace. Or maybe you can just reuse the same
interpreter for each use of the script.