如果在cmd中运行某个python代码,出现下面的错误
File "vido_pic.py", line 29
frame = cv2.resize(frame,(1280,720))
^
TabError: inconsistent use of tabs and spaces in indentation
这个错误的意思是说IDE分不清tab和空格,说明你的代码中混用了tab和空格。
为什么会出现这个错误?
因为Python区分块级别是通过Space空格和Table制表来进行区分的,并且对这两种分隔符都有相当严厉的规定,要么都用空格键缩进,要么都用tab键缩进,不能混用。在一个代码块中,如果第一行的缩进符号为2个Table,那么块内的所有代码都该用2个Table来缩进,如果第一行代码是2个空格缩进,那么块内余下所有代码都该是2个空格缩进。
解决办法:
第一,把代码从别处复制进来PyCharm,再点击运行,如果可以就不需要执行第二步。
第二,如果第一步无法解决问题,运行仍然报错:TabError: inconsistent use of tabs and spaces in indentation,需要格式化代码:
具体操作是:Code -->Reformat Code
参考链接:
1.https://blog.csdn.net/u014116780/article/details/84451569?ops_request_misc=&request_id=&biz_id=102&utm_term=TabError:%20inconsistent%20use%20of%20&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-1-.pc_search_all_es&spm=1018.2226.3001.4187
2.https://blog.csdn.net/jamesdodo/article/details/105116670