import execjs
# 读取到js字符串
with open('v1.js', mode='rb') as f:
js_string = f.read().decode('utf-8')
JSCode = execjs.compile(js_string)
# 调用js代码,如果有参数则依次往后逗号,写
res = JSCode.call('test', 'eric')
print(res)
js文件中正常写代码即可。
import execjs
# 读取到js字符串
with open('v1.js', mode='rb') as f:
js_string = f.read().decode('utf-8')
JSCode = execjs.compile(js_string)
# 调用js代码,如果有参数则依次往后逗号,写
res = JSCode.call('test', 'eric')
print(res)
js文件中正常写代码即可。