将JavaScript变量传递给Python [英] Passing JavaScript variable to Python

查看:148
本文介绍了将JavaScript变量传递给Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

#!/usr/bin/python
print "This is python."

print "<script type="text/javascript">
          var pass_to_python = new Number(7)
       </script>"

the_number = pass_to_python???

如何在python中获取pass_to_python?

How do I get the pass_to_python in python?

推荐答案

使用pyv8,您可以在Python中执行javascript。

With pyv8 you can execute javascript from within Python.

import PyV8

class Global(PyV8.JSClass):
    pass

with PyV8.JSContext(Global()) as ctxt:
    the_number = ctxt.eval("var pass_to_python = new Number(7)")

参见 http://code.google.com/p/pyv8/

这篇关于将JavaScript变量传递给Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆