Issue1827
Created on 2011-12-13.03:24:47 by neelemab, last changed 2012-04-01.19:03:30 by amak.
File name |
Uploaded |
Description |
Edit |
Remove |
Jython252Test.zip
|
neelemab,
2011-12-13.03:24:47
|
|
|
|
msg6742 (view) |
Author: Neelema (neelemab) |
Date: 2011-12-13.03:24:47 |
|
Copy of issue 1826
|
msg6764 (view) |
Author: Jeff Allen (jeff.allen) |
Date: 2012-01-28.21:39:48 |
|
Suggest 1826 be closed as this one contains a fuller example of what the user is having trouble with. The text from 1826 is this:
======
I created a script as "svc_params['SH_CAMPAIGN_ID'] = 'CAMPAIGN_ID'"
I compiled and executed the script in java using jython compiler and interpreter.
I am trying to extract script variables in java object using PyDictionary. PyDictionary constructor does not allow assigning the reference to the internal variable Map. So i am not able to get the scripts variable values in PyDictionay(Java).Is there any way where i can get those variables to Java. The same code works for 2.2.1 but not for 2.5.2. Please find my samples files attached. Please let me know if you need more details.
======
|
msg6766 (view) |
Author: Jeff Allen (jeff.allen) |
Date: 2012-01-28.21:48:10 |
|
The change of behaviour from 2.2.1 to 2.5.2 might be considered an issue (in need of documentation?), but looking athe code, the motive appears to have been an improvement.
On the whole, I think this were better considered a usage question than an issue.
The PyDictionary accepts and initial value for its Map, but it makes a private copy. The client can access it with PyDictionary.getMap(). That's a way I haven't tried as there appears to be a cleaner way.
This code, adapted from the user's example works for me on 2.5.2:
package X;
import org.python.core.CompileMode;
import org.python.core.Py;
import org.python.core.PyCode;
import org.python.core.PyDictionary;
import org.python.core.PySystemState;
import org.python.util.PythonInterpreter;
public class SolveIssue1827 {
public static void main(String[] args) {
// Compile the example program for the Python interpreter
String scriptSource = "svc_params['SH_CAMPAIGN_ID'] = 'CAMPAIGN_ID'";
PyCode pyCode = Py.compile_flags(scriptSource, "<string>", CompileMode.exec,
Py.getCompilerFlags(0, false));
// Create an interpreter
PySystemState.initialize();
PythonInterpreter interp = new PythonInterpreter(null);
// Create a dictionary for exchange
PyDictionary ioDictionary = new PyDictionary();
interp.set("svc_params", ioDictionary);
// Run the code and show that the exchange dictionary contains the result
interp.exec(pyCode);
System.out.println("*************** " + ioDictionary);
}
}
I get the output:
*************** {'SH_CAMPAIGN_ID': 'CAMPAIGN_ID'}
Close?
Jeff
|
msg6824 (view) |
Author: Alan Kennedy (amak) |
Date: 2012-03-19.17:58:54 |
|
Any input from requester on this issue?
Have you tried Jeffs solution?
Does it work or not?
|
msg7018 (view) |
Author: Alan Kennedy (amak) |
Date: 2012-04-01.19:03:30 |
|
[Jeff]
> On the whole, I think this were better considered a usage question than an issue.
and
[Jeff]
> Close?
And no further input from requester.
Closing.
|
|
Date |
User |
Action |
Args |
2012-04-01 19:03:30 | amak | set | status: open -> closed resolution: works for me messages:
+ msg7018 |
2012-03-19 17:58:54 | amak | set | priority: normal nosy:
+ amak messages:
+ msg6824 |
2012-01-28 21:48:10 | jeff.allen | set | nosy:
+ fwierzbicki messages:
+ msg6766 |
2012-01-28 21:39:49 | jeff.allen | set | nosy:
+ jeff.allen messages:
+ msg6764 |
2011-12-13 03:24:47 | neelemab | create | |
|