简体   繁体   English

Python 上的 NodeJS:不需要定义

[英]NodeJS on Python : require not defined

i'm trying to run javascript on my python script and i got this error: js2py.internals.simplex.JsException: ReferenceError: require is not defined我正在尝试在我的 python 脚本上运行 javascript 并且我收到此错误: js2py.internals.simplex.JsException: ReferenceError: require is not defined

here is my small python script:这是我的小 python 脚本:

import js2py

context = js2py.EvalJs(enable_require=True)

code1 = '''
var fs = require('fs');
var File = fs.readFileSync('C:\\Users\\SAMSUNG\\Dropbox\\SB.crx', 'base64');
console.log(File);
'''
f = js2py.eval_js(code1)
print(f) 

Note you enable require in your context object, and then you do not use it anywhere.请注意,您在context object 中启用了require ,然后您不要在任何地方使用它。 What you want is to execute directly in the context:您想要的是直接在上下文中执行:

context.execute(code1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM