From: Ype K. <yk...@xs...> - 2002-02-17 10:44:08
|
Branko, >>Hello, >> >I just recently discovered jython and it seems like dream come true! :) >But I got stuck at the very beginning! Could anyone please help me with >this, I can send send code examples if necessary: >> >Q1: I have a python application that I got from the web (I don't understandmuch of the python code). It is comprised of many .py files which all reside in one directory. If I call the main .py script by invoking standard python windows interpreter in the same command prompt line everything works fine. >But...when I want to call main script from my java code like: >interp.execfile(myscript.py)I get all import error messages: cannot import module, name etc. >Is the solution related to the python.home parameter? How do I fix this? The standard interpreter puts the current directory in sys.path when it starts a script from the shell command line. You'll have to do this yourself when you use interp.execfile('myscript.py'). (sys.path contains the directories from which modules can be imported.) >> >Q2: I have to send parameters to the main python script on invocation. Can I do that from interp.execfile(myscript.py -param a)? Is there any other way to do this? The standard interpreter takes the args from the shell command line and puts them in sys.argv. Again, you'll have prepare sys.argv yourself. You might also pass a namespace (ie. a dictionary) execfile() with '__name__' set to '__main__'. Any other var/value combination can be used to pass things on. You can do all of this in python code or java code. >Thanks in advance. Jython is like gift from Gods solution for my >problems...well only if I make it work. My pleasure. You will. Have fun, Ype -- |