73rhodes/node-python

语言: JavaScript

git: https://github.com/73rhodes/node-python

与NodeJS中长期运行的Python子进程通信。
Communicate with a long-running Python child process from NodeJS.
README.md (中文)

因为它是py

NodeJS的超简单包装器,可以与Python shell进行编程交互。允许使用Node中基于Python的工具。

安装

npm安装python

NPM Stats

NPM Downloads

这个例子启动一个python子进程,为python命令读取stdin,将它们传递给python shell并运行带有结果输出的回调方法。状态在调用之间保留在shell中。

// ------
// app.js
// ------
var python=require('python').shell;

// a callback to handle the response
var mycallback = function(err, data) {
   if (err) {
     console.error(err);
   } else {
     console.log("Callback function got : " + data);
   }
};

// to test, read and execute commands from stdin
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
   python(chunk, mycallback);
});

执照

WITH

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

node-python

A super-simple wrapper for NodeJS to interact programatically with the Python shell. Enables the use of Python-based tools from Node.

Installation

npm install python

NPM Stats

NPM Downloads

Example

This example starts a python child process, reads stdin for python commands, pipes them through to the python shell and runs the callback method with the resulting output. State is preserved in the shell between calls.

// ------
// app.js
// ------
var python=require('python').shell;

// a callback to handle the response
var mycallback = function(err, data) {
   if (err) {
     console.error(err);
   } else {
     console.log("Callback function got : " + data);
   }
};

// to test, read and execute commands from stdin
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
   python(chunk, mycallback);
});

License

MIT