V8 的 Python 封裝:PyV8
PyV8 是Google V8 引擎的 Python 語言封裝,這是 Python 和 JavaScript 對象之間的橋,支持在 Python 腳本中調用 V8 引擎。
>>> import PyV8 >>> ctxt = PyV8.JSContext() # create a context with an implicit global object >>> ctxt.enter() # enter the context (also support with statement) >>> ctxt.eval("1+2") # evalute the javascript expression 3 # return a native python int >>> class Global(PyV8.JSClass): # define a compatible javascript class ... def hello(self): # define a method ... print "Hello World" ... >>> ctxt2 = PyV8.JSContext(Global()) # create another context with the global object >>> ctxt2.enter() >>> ctxt2.eval("hello()") # call the global object from javascript Hello World # the output from python script
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!