【发布时间】:2018-09-17 21:35:59
【问题描述】:
文件夹目录结构如下:
folder_A
folder_A/a.py
folder_A/subfolder_AA/b.py
folder_A/subfolder_AA/subsubfolder_testvideos/a.avi
a.py 看起来像...
import cv2
import argparse as ap
def run(source=0, dispLoc=False):
cam=cv2.VideoCapture(source)
while True:
ret, img = cam.read()
if not ret:
exit()
if(cv2.waitKey(10)==ord('p')):
break
cv2.imshow("image",img)
cv2.destroyWindow("image")
# Other scripts here....
if __name__ =="__main__":
parser = ap.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-d', "--deviceID", help="Device ID")
group.add_argument('-v', "--videoFile", help="Path to Video File")
parser.add_argument('-l', "--dispLoc", dest="dispLoc",
action="store_true")
args = vars(parser.parse_args())
if args["videoFile"]:
source = args["videoFile"]
else:
source = int(args["deviceID"])
run(source, args["dispLoc"])
a.py 尝试导入并运行 b,而 b 需要 argparse。
如果我只是从终端运行 b.py,运行 b 的命令将是
python b.py -v subsubfolder_testvideos/a.avi
我正在尝试运行 a.py 并让 b.py 在其中运行。
在 a.py 文件中,我编写了如下代码。
import sys
sys.path.append('~/Desktop/folder_A')
sys.path.append('~/Desktop/')
from os import system
import subprocess
subprocess.call(["python", "b.py","-v testvideos/a.avi"], cwd="/subfolder_AA/", shell=True)
并且输出错误是 FileNotFoundError: [Errno 2] No such file or directory: '/subfolder_AA/': '/subfolder_AA/'
此错误是否来自我使用 subprocess.call 的错误命令?我该如何解决这个问题?
【问题讨论】:
标签: python directory subprocess argparse