Pyv8 learn python and JavaScript variables for interaction _python

Source: Internet
Author: User

Python Gets the value in JavaScript

Copy Code code as follows:

Import PyV8

With Pyv8.jscontext () as ENV1:
Env1.eval ("" "
Var_i = 1;
Var_f = 1.0;
var_s = "Test";
Var_b = true;
""")
VARs = Env1.locals
Var_i = Vars.var_i
Print Var_i


JavaScript gets the value inside python

Copy Code code as follows:

Import PyV8

With Pyv8.jscontext () as ENV1:
Env1.securitytoken = "Foo"
Env1.locals.prop = 3
print int (env1.eval ("prop"))

function interaction in Python and JavaScript

Python calls the functions in JavaScript Python calls Func can use the function functions in JS

Copy Code code as follows:

Import PyV8

with Pyv8.jscontext () as Ctxt:
    func = Ctxt.eval (""
                 (function ()
                 {
                     function A ()
                     {
                          return "ABC";
                    }

return a ();
})
""")
Print func ()

That's OK.

Copy Code code as follows:

Import PyV8

with Pyv8.jscontext () as Ctxt:
    func = Ctxt.eval (""
                     function A ()
                     {
                         return "ABC";
                    }

Function C ()
{
Return "ABC";
}
""")
A = CTXT.LOCALS.A
Print a ()

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.