python-shell icon indicating copy to clipboard operation
python-shell copied to clipboard

Can we return the result from python-shell ?

Open Pranjilagrawal opened this issue 4 years ago • 4 comments

Here is my code in node.js file

function emailVerification(ordernumber,orderdate,key){ console.log(ordernumber); var options = { mode: 'text', args: ['id','pwd,ordernumber,'passkey',orderdate,key] }; let pyshell = PythonShell.run('email_check_driver.py', options, function (err,res) { console.log("Result",res) if (err) throw err; console.log('finished'); return res #######( Can i return the result like this?) }); pyshell.on('message', function (message) { // received a message sent from the Python script (a simple "print" statement) console.log('Message',message); return message ####### ( Or Can i return the result like this?) }); }

I want to fetch data here in the variable when calling the function. Is it Possible?

var json_data = emailVerification('9HPDCHKA36','May 28, 2021, 2:51:51 PM','Order Request') console.log("json",json_data)

Pranjilagrawal avatar May 31 '21 10:05 Pranjilagrawal

You'd do something like this I guess

const options = {
  mode: "text",
};
const pyshell = new PythonShell("email_check_driver.py", options);

function emailVerification(ordernumber, orderdate, key) {
  console.log(ordernumber);
  let Result;
  pyshell.send(ordernumber);
  pyshell.on("message", function (message) {
    // received a message sent from the Python script (a simple "print" statement)
    Result = message;
  });
  return Result;
}

shivamsingha avatar Jun 06 '21 05:06 shivamsingha

Thank you. I will try

On Sun, 6 Jun, 2021, 11:19 AM Shivam, @.***> wrote:

You'd do something like this I guess

const options = { mode: "text",};const pyshell = new PythonShell("email_check_driver.py", options); function emailVerification(ordernumber, orderdate, key) { console.log(ordernumber); let Result; pyshell.send(ordernumber); pyshell.on("message", function (message) { // received a message sent from the Python script (a simple "print" statement) Result = message; }); return Result;}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/extrabacon/python-shell/issues/244#issuecomment-855343231, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALMBUMCRF3SBSMMS5JH6YITTRMD63ANCNFSM452TSZEA .

Pranjilagrawal avatar Jun 07 '21 18:06 Pranjilagrawal

You'd do something like this I guess

const options = {
  mode: "text",
};
const pyshell = new PythonShell("email_check_driver.py", options);

function emailVerification(ordernumber, orderdate, key) {
  console.log(ordernumber);
  let Result;
  pyshell.send(ordernumber);
  pyshell.on("message", function (message) {
    // received a message sent from the Python script (a simple "print" statement)
    Result = message;
  });
  return Result;
}

This doesn't work with 'pythonError'

seaninho avatar Oct 12 '21 19:10 seaninho

Are there any updates on this?

zeke-john avatar May 30 '22 23:05 zeke-john