簡體   English   中英

使用 python-shell 將 arguments 從 nodejs 傳遞到 python 腳本

[英]Pass arguments from nodejs to python script using python-shell

我正在嘗試在 Nodejs 項目中運行 python 腳本。 Everything works pretty well passing a local video URL in my python script, but I need to retrieve the video URL from my MongoDB and pass it to the python script. 有沒有辦法我可以做到這一點? 我進行了一些研究,但找不到解決此問題的方法。

app.get('/test', callName); 
  
function callName(req, res) { 
  PythonShell.run('ai_part/test.py', null, function (err) {  
    if (err) throw err;
    console.log('finished');
  });
} 

Python代碼:

#Loading the video input
cap = cv2.VideoCapture('test.wmv')

_, img = cap.read()
height, width, _ = img.shape
copy = img.copy()

不知道夠不夠清楚,不過需要將從我的mongo數據庫獲取的視頻URL傳到python function'Video.Capture 提前致謝!

就像文檔告訴你的那樣,

function callName(req, res) {
  let options = {
    mode: 'text',
    args: [res]
  };
  PythonShell.run('ai_part/test.py', options, function (err) {  
    if (err) throw err;
    console.log('finished');
  });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM