ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> Jython-dev
Jython-dev
Re: [Jython-dev] Looking for ways to embed Jython in Java.
by Johan Hahn other posts by this author
Nov 8 2004 9:45PM messages near this date
Re: [Jython-dev] Looking for ways to embed Jython in Java. | [Jython-dev] Can't Install Jython
You should post these kind of questions to the jython users list. This is the 
developer list. Since I've already answered them though, I'll post the reply 
here (just this time).

"Colbert Philippe" wrote:
> - Can we implement interface directly in Jython?  If yes, how (example)?

You can't create an interface in Jython that you use as an interface when 
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 Java).

class ActionListener:
   def actionPerformed(e):
      raise NotImplementedError

> - Can we embed a Jython script in a way that the script can be called several 
> times and keep its environment?

Why not just save state between invocations to disk? If your state data is 
complicated the task can be simplified by using the pickle module.

<code> 
import pickle

class NotSoComplicatedState:
   def __init__(self):
      self.invocations = 0

try:
   counter = pickle.load(open('my.state'))
except IOError:
   counter = NotSoComplicatedState()

counter.invocations += 1
print 'script called for the %i:th time' % counter.invocations

pickle.dump(counter, open('my.state', 'w'))
</code> 


...johahn


-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_idU88&alloc_id065&opÌk
_______________________________________________
Jython-dev mailing list
Jython-dev@[...].net
https://lists.sourceforge.net/lists/listinfo/jython-dev
Thread:
Colbert Philippe
Kent Johnson
Johan Hahn

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved