【发布时间】:2019-06-20 09:18:15
【问题描述】:
我在 nodejs 上运行硬件,并且我在 python3 中编写了机器学习代码。 我想从nodejs(javascript)调用python3程序并将数据作为参数传递给python程序。
我发现了一些方法,例如使用 spawn、python-shell 等,它们通过创建子进程来调用 python。
但我想从父进程本身调用 python,而不创建子进程。 意味着,只有进程,即父 nodejs 进程应该运行。
test.py
def someFunction():
#some code here
#print the arguments received.
someFunction ()
test.js
call test.py from this test.js and need to pass arguments to python program as well.
call test.py with arguments as ('xyz', 'abc')
我期望输出: xyz abc
在不创建和启动子进程的情况下找不到任何调用方式。
【问题讨论】:
-
Python 是 interpreted language,我认为没有办法在不启动解释器进程的情况下运行未编译的纯 Python 代码。
标签: javascript node.js python-3.x