难以运行该程序

时间:2015-11-16 05:19:54

标签: python numpy

我试图运行下面的程序,但遇到了这个错误。

追踪(最近一次呼叫最后一次):

$input= "words trying to compare";

preg_match("/\b{$input}\b/", "these are a lot of words that i'm trying to compare") 
              // ^this might contain multiple words, but the same as ^^ these
echo "match is found";

我正在使用的代码如下所述:

File "C:\Users\danil\Desktop\HK1.py", line 76, in <module>
img1c = cv2.imread(sys.argv[1])

IndexError: list index out of range

1 个答案:

答案 0 :(得分:0)

if __name__ == '__main__':
 img1c = cv2.imread(sys.argv[1])
 img2c = cv2.imread(sys.argv[2])

需要更改为

if __name__ == '__main__'
    if sys.argv[2:]:
        arg1 = sys.argv[1]
        arg2 = sys.argv[2]
    else:
        print('need at least 2 arguments')
        sys.exit(2)
    img1c = cv2.imread(arg1)
    img2c = cv2.imread(arg2)
    ...

然后需要使用2个文件名调用它(除了脚本.py)。