[kepler-dev] PythonScript actor

Christopher Brooks cxh at eecs.berkeley.edu
Wed Mar 12 13:45:07 PDT 2008

Hi Dan,
There are some examples in $PTII/ptolemy/actor/lib/python/test/auto
Other than that, I don't know of anything.

It could easily be that we have to set the python.home property.
This would make Jython less useful because it would make deployment
difficult because deployment would require installing the Jython
directory.  The proper solution for the the Jython developers is
to ship one jar file that contains the files in the python.home
directory.  The other problem with Jython is that the jar cache
wants to write on the disk.  

I can look at modifying $PTII/bin/vergil so that it includes
the python.home hack.  Or, perhaps the Jython actors should
be smart enough to set this themselves by looking for the jython.jar
file in the classpath?  

BTW - the PythonScript actor can change, I don't think there is
much use of it, so evolving it to something more useful seems



    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) :
        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)
    Now, I CAN get the above script to work OK when I add the following to 
    the Kepler java startup command
    i.e. when I create a new property 'python.home = <path to my jython home 
    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