圆月山庄资源网 Design By www.vgjia.com

python取得javascript里面的值

复制代码 代码如下:
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取得python里面的值
复制代码 代码如下:
import PyV8

with PyV8.JSContext() as env1:
    env1.securityToken = "foo"
    env1.locals.prop = 3
    print int(env1.eval("prop"))

python和javascript里面的函数交互

python调用javascript里面的函数 python调用func就可以使用js里面的function函数了

复制代码 代码如下:
import PyV8

with PyV8.JSContext() as ctxt:
    func = ctxt.eval("""
                (function ()
                {
                    function a()
                    {
                        return "abc";
                    }

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

这样也可以

复制代码 代码如下:
import PyV8

with PyV8.JSContext() as ctxt:
    func = ctxt.eval("""
                    function a()
                    {
                        return "abc";
                    }

                    function c()
                    {
                        return "abc";
                    }
                """)
    a = ctxt.locals.a
    print a()

标签:
python,javascript,pyv8学习

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com