I am calling a python script using PythonShell through this code :
let python_options = {
mode: "text",
pythonPath: "python",
scriptPath:"./python/",
args: ["-fil '"+file_path+"'"]
};
let pyshell = new PythonShell.PythonShell('my_script.py',python_options);
pyshell.on('message', function(message) {
console.log(message);
});
pyshell.end( function(err,code,signal) {
if (err) console.log("Error %j", err);
console.log('The exit code was: ' + code);
console.log('The exit signal was: ' + signal);
// console.log("results: %j", results);
res.send(code);
});
then within my Python script I do
import argparse
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-fil", '--file', required=False, default=None)
The error message I'm getting when calling the script is
my_script.py: error: unrecognized arguments: -fil 'path_to_the_file'
My issue is that the shell passes "-fil path_to_the_file" to the CLI, which gets interpreted as one argument by argparse, instead of -fil path_to_the_file which would be correctly interpreted by argparse.
How can I remove the quotes in PythonShell ?
"-fil " "paht_to_the_file"works in the CLI in case my comment above was unclear. But the PythonShell call still fails with the same error message.argparseinstance. So I'm calling it with--filealready and yes it works in the CLI only. pyhton 3.7 on windows