Python打印中的语法错误

时间:2015-12-15 16:45:48

标签: python printing

在python / linux中运行这段代码时:

import numpy as numpy
import cv2
import os

os.system('clear')
cap = cv2.VideoCapture('vid_1.mp4')

q = 0 
while(cap.isOpened()):
   ret, frame == cap.read()
   if ret == True:
      q += 1  
      print("Frame No: " + q)


   gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
   cv2.imshow('frame',gray)

   if cv2.waitKey(1) & 0xFF == ord('q'):
      break

      cap.release()
      cv2,destroyAllWindows()

我遇到以下错误:

 print("Frame No: " + q)
                      ^
 IndentationError: unindent does not match any outer indentation level

此外, os.system(' clear')似乎没有清除屏幕。我认为基本缺失了,有什么可以取悦的?感谢

2 个答案:

答案 0 :(得分:1)

if ret == True:
   q += 1  
   print("Frame No: " + q)

看来这行代码只缩进了两个空格,而其他行则缩进了四个空格。

if ret == True:
     q += 1  
     print("Frame No: " + q)

这会有用吗?

答案 1 :(得分:1)

enter image description here

你正在混合标签和空格,这会混淆Python。使用其中一个,而不是两个。空间是可取的。

相关问题