[kepler-dev] PythonScript actor
Dan Higgins
higgins at nceas.ucsb.edu
Wed Mar 12 12:26:13 PDT 2008
Hi Christopher,
I have been playing with the PythonScript actor in Kepler/PTII (as
part of an effort to learn Python/Jython). I am familiar with the
examples in $PTII/ptolemy/actors/lib/python/ and the Python actors works
fine with those examples in Kepler and PTII. Are there any more examples
of Python scripts in PTII?
One reason I ask is that I was trying to get the script below to
work in Kepler and PTII and I run into several errors, athough it works
OK when executed directly with the jython command line interpreter. (The
problem is with importing the os module and in finding the file named on
the the input port)
import os
from ptolemy.data import IntToken
class Main :
"Number of lines"
def fire(self) :
if not self.input.hasToken(0) :
return
t = self.input.get(0)
fs = t.toString()
# Note the fs includes quotes at both ends that must be removed !
print fs[1:len(fs)-1]
file = open(fs[1:len(fs)-1],'r')
lines = file.readlines();
cnt = len(lines)
cwd = os.getcwd()
st = IntToken(cnt)
self.output.broadcast(st)
Now, I CAN get the above script to work OK when I add the following to
the Kepler java startup command
-Dpython.home=/Users/higgins/jython2.2.1
i.e. when I create a new property 'python.home = <path to my jython home
directory>
I guess I am just questioning the setup for the PythonScript actor in
Kepler and PTII. Setting python.home does seem to work OK when one has a
jython installation but I haven't figured out how to set up jython
within Kepler for more complicated scripts. In any case, it looks like
just adding jython.jar to the classpath is not sufficient for some scripts.
Dan Higgins
More information about the Kepler-dev
mailing list