
前一段时间用 node.js 做项目,感觉 node.js 在服务器方面游刃有余,但是其他方面难望 Python 之项背。于是撸了一个可以在 node.js 中调用 Python 代码的模块。支持 node.js ,io.js , nw.js 。
例子如下:
var python = require('python.js'); var os = python.import('os'); var path = require('path'); assert(os.path.basename(os.getcwd()) == path.basename(process.cwd())); 支持以异步模式调用 Python 的代码:
def test(): try: ## do samething except Exception as e: raise e return 'done' PYMODULE.test.async = true; PYMODULE.test(function (result, error) { if (!error) console.log(result); }); 最后放上项目地址:
https://github.com/monkeycz/python.js
1 ugmc 2015-03-20 18:34:55 +08:00 via Android 挺好 |