使用 PyV8 从 Python 函数返回 `undefined`? [英] Return `undefined` from Python function with PyV8?

查看:29
本文介绍了使用 PyV8 从 Python 函数返回 `undefined`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PyV8,我想使用 undefined 调用 javascript 函数.似乎同时评估 undefinednull 返回 Python 的 None 值:

<预><代码>>>>evaljs("未定义")没有任何>>>evaljs("null")没有任何

当然,问题在于它们在 javascript 中并不相同:

<预><代码>>>>evaljs("未定义 === null")错误的错误的>>>evaljs("undefined") == evaljs("null")没有任何没有任何真的

有什么好的方法可以做到这一点吗?我实际上想编写一个可从 javascript 调用的 Python 函数,它在某些情况下返回 undefined,在其他情况下返回 null.

编辑SSCCE-ness:

导入 PyV8上下文 = PyV8.JSContext()def evaljs(s):有上下文:res = context.eval(s)打印资源返回资源

解决方案

答案是:在当前版本中没有办法做到这一点.

I'm using PyV8 and I'd like to call a javascript function with undefined. It seems that evaluating both undefined and null return Python's None value:

>>> evaljs("undefined")
None
>>> evaljs("null")
None

The problem, of course, is that they're not the same in javascript:

>>> evaljs("undefined === null")
False
False
>>> evaljs("undefined") == evaljs("null")
None
None
True

Is there any nice way to go about doing this? I'd actually like to write a Python function, callable from javascript, which returns undefined in certain cases and null in other cases.

EDIT for SSCCE-ness:

import PyV8

context = PyV8.JSContext()

def evaljs(s):
    with context:
        res = context.eval(s)
        print res
        return res

解决方案

The answer is: in the current version there is no way to do this.

这篇关于使用 PyV8 从 Python 函数返回 `undefined`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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