我有一个在python脚本中执行的shell脚本,我想将两个变量作为参数传递给该脚本。我使用了$ sign,但它不起作用。这是shell脚本:
path='/home/ranim/Documents/mmdet/media/Page_00287_jpg.rf.6a823c5ce3894f223a0e8f4ec20b11b2/article1'
save='/home/ranim/Documents/mmdet/media/Page_00287_jpg.rf.6a823c5ce3894f223a0e8f4ec20b11b2/article1/annotations.json'
call('python "/home/ranim/Documents/mmdet/mmdetection/tools/test.py" \
"/home/ranim/Documents/mmdet/models/second_model_conf.py" \
"/home/ranim/Documents/mmdet/models/second_model_checkpoint.pth" \
--cfg-options data.test.ann_file=$save \
data.test.img_prefix=$path \
--format-only \
--options "jsonfile_prefix=path"', shell=True)发布于 2021-07-25 23:27:57
我猜字符串插值可以用来将Python变量传递给call命令的args。例如,如果使用fstring,代码将如下所示:
path='/home/ranim/Documents/mmdet/media/Page_00287_jpg.rf.6a823c5ce3894f223a0e8f4ec20b11b2/article1'
save='/home/ranim/Documents/mmdet/media/Page_00287_jpg.rf.6a823c5ce3894f223a0e8f4ec20b11b2/article1/annotations.json'
call(f'python "/home/ranim/Documents/mmdet/mmdetection/tools/test.py" \
"/home/ranim/Documents/mmdet/models/second_model_conf.py" \
"/home/ranim/Documents/mmdet/models/second_model_checkpoint.pth" \
--cfg-options data.test.ann_file={save} \
data.test.img_prefix={path} \
--format-only \
--options "jsonfile_prefix=path"', shell=True)https://stackoverflow.com/questions/68519873
复制相似问题