Node.js中的python shell不执行python脚本
我正在努力学习JavaScript。以前是用Python编写代码的。我喜欢将一些Python程序链接到Node.js中运行。使用python shell中的代码运行我的python脚本,但遇到了以下错误,我甚至无法理解:Node.js中的python shell不执行python脚本,python,node.js,Python,Node.js,我正在努力学习JavaScript。以前是用Python编写代码的。我喜欢将一些Python程序链接到Node.js中运行。使用python shell中的代码运行我的python脚本,但遇到了以下错误,我甚至无法理解: /Users/cadellteng/AtomProjects/useSpawn/node_modules/python-shell/index.js:217 return callback(err);
/Users/cadellteng/AtomProjects/useSpawn/node_modules/python-shell/index.js:217
return callback(err);
^
TypeError: callback is not a function
at PythonShell._endCallback (/Users/cadellteng/AtomProjects/useSpawn/node_modules/python-shell/index.js:217:24)
at terminateIfNeeded (/Users/cadellteng/AtomProjects/useSpawn/node_modules/python-shell/index.js:158:39)
at ChildProcess.<anonymous> (/Users/cadellteng/AtomProjects/useSpawn/node_modules/python-shell/index.js:131:13)
at ChildProcess.emit (events.js:316:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
你好,派伊
name = input('What is your name?\n>>> ') # John Doe
print('Hello '+ name +'!') # expects output as 'Hello John Doe!'
我试图将python放在main()
中,但它似乎不起作用
我相信python脚本可以工作,因为当我从终端执行它时,它执行得很好。请看
PythonShell.run
的参数是脚本名、选项对象和回调。所以回调是第三个参数
在您的情况下,您将在选项应该位于的位置传递回调。第三个参数仍然是未定义的,实际上它不是一个函数
name = input('What is your name?\n>>> ') # John Doe
print('Hello '+ name +'!') # expects output as 'Hello John Doe!'