Re: [Jython-dev] jythinc called from java code
by Michal Sankot other posts by this author
Oct 23 2003 2:40PM messages near this date
Re: [Jython-dev] New 'Projects Using Jython' page on wiki, was SARNavigator users Jython
|
[Jython-dev] bad link
That works fine.
With direct rewriting of argv, there is no need to set args globaly for
PythonInterpreter and thus initialization can be:
> PythonInterpreter.initialize(System.getProperties(),postProp,null);
which is a bit more clear codingwise.
Thanks for your help Jeff,
Michal
----- Original Message -----
> You can change argv like this:
>
> import sys
> sys.argv=['a','new','set','of','args']
>
> Or you could just replace the last one, if you need
> the same flags for jythonc:
>
> sys.argv[-1]='newfile.py'
>
> You don't need to import main multiple times. Your
> code could be
>
> PythonInterpreter.initialize(System.getProperties(),postProp,new
> String[]{"","--jar","g.jar","d:\\_p\\jin.py"});
> PythonInterpreter pi = new PythonInterpreter();
> pi.exec("import main");
> pi.exec("main.main()");
> pi.exec("import sys");
> String[] extraFiles = {"file1.py","file2.py","file3.py"};
> for (int i=0;i<extraFiles.length;++i) {
> pi.exec("sys.argv[-1]='"+extraFiles[i]+"'");
> pi.exec("main.main()");
> }
>
> -----Original Message-----
>
> Good, have it working for one run now.
>
> code is:
> -----------------------------
> PythonInterpreter.initialize(System.getProperties(),postProp,new
> String[]{"","--jar","g.jar","d:\\_p\\jin.py"});
> PythonInterpreter pi = new PythonInterpreter();
> pi.exec("import main");
> pi.exec("main.main()");
> -----------------------------
>
> But, it I need to run it with different paramteters on different files.
> Trying to call PythonInterpreter.initialize() with different arguments
> doesn't work, as it checks if it was initialized already and if so, it
> returns immediatelly and doesn't set anything. Calling 'PythonInterpreter
> pi2 = new PythonInterpreter();' doesn't help either.
>
> Is there a way, how to set argv in Python ?
> So that my code would then be
>
> pi.exec(".......change argv ......");
>
> pi.exec("import main");
> pi.exec("main.main()");
> pi.exec(".......change argv ......");
>
> pi.exec("import main");
> pi.exec("main.main()");
> ......
>
> Michal
>
> ----- Original Message -----
> >
> > Then you probably need to prepend a dummy argv[0].
> > When you start jython with a .py file, such as is
> > done from the jython script, the name of the .py
> > file is the first element of argv. Your first element
> > of argv is --jar. The code is expecting the first
> > argument to be the second element. Try this:
> >
>
String[]{"jythonc.py","--jar","g.jar","--compiler","javac","d:\\_p\\jin.py"}
-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community? Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
Jython-dev mailing list
Jython-dev@[...].net
https://lists.sourceforge.net/lists/listinfo/jython-dev
|