python.js ,一个在 node.js 中调用 Python 代码的模块

2015-03-20 17:37:26 +08:00
 monkeycz

前一段时间用 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

3944 次点击
所在节点    Node.js
3 条回复
ugmc
2015-03-20 18:34:55 +08:00
挺好
gamexg
2015-03-21 09:33:42 +08:00
生产环境用起来怎么样?
现在我 nodejs 调 python 是通过 rest.post(url) 来使用的。
monkeycz
2015-03-21 14:59:39 +08:00
@gamexg 目前手边有两个已发布的项目在用这个模块。项目里 node.js 和 Python 的代码比例都是接近 1:1,通过 python.js 进行桥接。暂时没发现什么问题。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/178296

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX