From: Joern E. <Joe...@mi...> - 2001-07-30 13:21:21
|
Hi all. Here are now the latest results from my try to import within a script. Likely this will be the last e-mil from me. At the moment I'm the doc-writer-man because my practical work (I'm a student) will be finished in two weeks, therefore I have to write one report for my employer as well as one for the Fachhochschule (It's comparable to a college). Ok guys, here we go: > On Wed, 25 Jul 2001, Joern Eckhoff wrote: > > now my script looks like this: > > > > # ----------- begin ob script > > import java > > java.lang.System.getProperty("python.home") > > java.lang.System.getProperty("python.path") > > > > import sys > > sys.path.append("c:\\program files\\jython;c:\\program files\\jython\\lib") > > This append may be the culprit. Sorry if I've missed this in earlier > mails, but for... > > sys.path.append("c:\\;c:\\windows\\desktop") > import test # a Jython script on my desktop > > The above does not work. sys.path is a list of individual directories, > rather than system directory representations (e.g. > ["\\path\\one", "\\path\\two"] instead of \\path\\one;\\path\\two). > Instead, if I use: > > sys.path.append("c:\\") > sys.path.append("c:\\windows\\desktop") > import test # a Jython script on my desktop > > All is well. So, give this a try: > > sys.path.append("c:\\program files\\jython\\Lib") # only one dir > # or > sys.path.extend( > ("c:\\program files\\jython", "c:\\program files\\jython\\Lib") > ) I've changed this part of my script and now it looks like this: import sys sys.path.append("c:\\program files\\jython") sys.path.append("c:\\program files\\jython\\lib") > > print "python.home: ",java.lang.System.getProperty("python.home") > > print "python.path: ",java.lang.System.getProperty("python.path") > > print "sys.path: ",sys.path > > print "sys.prefix: ",sys.prefix > > > > # Import support for strings > > import string > > > > # Get the value of the scalar node > > value = scriptinterface.getNodeValue(".1.3.6.1...") > > > > # Convert value to INT > > valueAsInt=string.atoi(value) > > > > # Add 1 to value > > valueAsInt=valueAsInt+1 > > > > # Set a limit of 8 for value > > if valueAsInt > 8: > > valueAsInt=1 > > > > # Convert valueAsInt back to string > > value=str(valueAsInt) > > > > # Write back (increased) value to node > > scriptinterface.updateValue(".1.3.6.1...",value,"CONST") > > # ----------- end ob script <snip> > > - the > > '.\\jars\\Lib' is the path leading to the jars containing all the > > class-files of the AgentSimulator. The module 'string.py' actually is > > present at 'c:\program files\jython\lib'. Doesn't it indicate the path to > > the modules is missing? Does jython use sys.path as well as python.path? > > Properties, like python.path, python.home and etcettera, are all about > initializing Jython. Java code takes steps to set Jython's system state > before actually creating the interpreter instance, and these property > values are what is used in these steps. The main step is > PythonInterpreter.initialize(), but remember that this method should be > called before instantiating an interpreter. After instantiation, Jython's > sys module as the final word. python.path is added to the sys.path during > initialization. Following that, what is in sys.path is the final word. Ok, I see. Then it wouldn't wonder that the script now works. There's only one blemish left. When starting the script _the first time_ (i.e. when PythonInterpreter is initialized the first time after restart) it results in a NoSuchMethodError thrown by the module string.py in line 418. I've attached the log-file, the script and my version of string.py (please see attached file.zip) to let you have a look at it. For me it looks like string.py couldn't find the module named strop.?. I've searched for it with mask *strop*.* at c:\ and all subfolders but the only file I've found was test_strop.py at c:\program files\Python\Lib\test. I guess everthing will be all right after adding strop.? to my installation. <snip> > Cheers, > Robert cu Joe |