为什么s1的结果不报:hello world ?

import execjs
s1="console.log('hello world')"
print('s1:',execjs.eval(s1))  # s1: None
s2="'red yellow blue'.split(' ')"
print('s2:',execjs.eval(s2))  # s2: ['red', 'yellow', 'blue']
阅读 1.6k
1 个回答

因为log返回值为空啦。

import execjs

jsFunc = '''
    function helloWorld(arg1){
        console.log('hello world')
        return arg1+'hello world';
    }
'''
jscontext = execjs.compile(jsFunc)
a = jscontext.call('helloWorld',233)
print(a)

可以设定函数 并指定返回值。

推荐问题