【发布时间】:2013-06-08 01:30:15
【问题描述】:
我正在使用 PyV8,我想用 undefined 调用一个 javascript 函数。似乎同时评估 undefined 和 null 返回 Python 的 None 值:
>>> evaljs("undefined")
None
>>> evaljs("null")
None
当然,问题在于它们在 javascript 中并不相同:
>>> evaljs("undefined === null")
False
False
>>> evaljs("undefined") == evaljs("null")
None
None
True
有什么好的方法可以做到这一点吗?我实际上想编写一个 Python 函数,可从 javascript 调用,它在某些情况下返回 undefined,在其他情况下返回 null。
编辑SSCCE-ness:
import PyV8
context = PyV8.JSContext()
def evaljs(s):
with context:
res = context.eval(s)
print res
return res
【问题讨论】:
-
@bfavaretto:我的意思是我想编写一个返回
undefined而不是null的Python函数 -
我错过了,抱歉。
标签: javascript python undefined v8 pyv8