public class Firstjavascript
{
public static void Main (String args[])
{
Pythoninterpreter interpreter = new Pythoninterpreter ();
Interpreter.execfile ("c:\\python27\\programs\\my_utils.py");//path, script name
pyfunction func = (pyfunction) interpreter.get ("Adder", pyfunction.class);//adder python function name
int a =, b = 2;
Pyobject pyobj = func.__call__ (New Pyinteger (a), new Pyinteger (b));//pass value, a B
System.out.println ("Anwser =" + pyobj.tostring ());
}//main
}
The resulting result is: Anwser = 2012
3. Execute the Python script directly using Java,
Create a script inputpy
View Plain
#open files
print ' Hello '
number=[3,5,2,0,6]
Print number
Number.sort ()
Print number
Number.append (0)
Print number
Print Number.count (0)
Print Number.index (5)
public class Firstjavascript
{
public static void Main (String args[])
{
Pythoninterpreter interpreter = new Pythoninterpreter ();
Interpreter.execfile ("c:\\python27\\programs\\input.py");
}//main
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service