Skip to content

Unclear documentation #258

@seaninho

Description

@seaninho

The Question:

The following code snippet is taken straight from your README file.

import {PythonShell} from 'python-shell';

let options = {
  mode: 'text',
  pythonPath: 'path/to/python',
  pythonOptions: ['-u'], // get print results in real-time
  scriptPath: 'path/to/my/scripts',
  args: ['value1', 'value2', 'value3']
};

PythonShell.run('my_script.py', options, function (err, results) {
  if (err) throw err;
  // results is an array consisting of messages collected during execution
  console.log('results: %j', results);
});

However, you fail to specify who catches the thrown err and where.

If I wrap the PythonShell.run code block like so

try {
  PythonShell.run('my_script.py', options, function (err, results) {
    if (err) throw err;
    // results is an array consisting of messages collected during execution
    console.log('results: %j', results);
  });
}
catch(error) {
  console.log(error);
}

Nothing prints out.

  1. How am I supposed to throw an error using the callback function?

  2. How am I supposed to catch an error?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions