【发布时间】:2021-07-22 14:27:21
【问题描述】:
我正在使用 nodejs 的 python-shell 包来触发 python 脚本,该脚本返回 SyntaxError: invalid syntax。
Nodejs 代码
const options = {
mode: 'text',
pythonPath: '/usr/bin/python3',
scriptPath: __dirname + '/script',
};
var pyshell = new PythonShell('test.py', options);
pyshell.send('hello');
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log(message);
});
// end the input stream and allow the process to exit
pyshell.end(function (err,code,signal) {
if (err) throw err;
console.log('The exit code was: ' + code);
console.log('The exit signal was: ' + signal);
console.log('finished');
});
Python 脚本
print(f'test')
错误
PythonShellError: File "/app/src/back/script/test.py", line 1
print(f'meas')
^
SyntaxError: invalid syntax
如果我使用命令:python3 test.py 运行脚本,我会打印出“test”这个词,但不会像我想要的那样使用 python-shell。 我的python版本是3.8.10
【问题讨论】: