python错误提示“TabError: inconsistent use of tabs and spaces in indentation”

在遍历打印10以内的奇数是出现“TabError: inconsistent use of tabs and spaces in indentation”的错误提示:

代码如下:

第一感觉没什么错误,但是当我设置显示“空格与制表符”时候,问题出现了,在第4、5行前由制表符,如图所示:

在if和continue前有制表符,所以执行的时候会提示“TabError: inconsistent use of tabs and spaces in indentation”

解决问题重新运行,结果OK。

亲测好使。。。

时间: 2024-08-23 10:56:40

python错误提示“TabError: inconsistent use of tabs and spaces in indentation”的相关文章

python运行错误---TabError: Inconsistent use of tabs and spaces in indentation

本文转载于:http://blog.csdn.net/sinat_36384705/article/details/71155379 首先这个错误的意思是:在缩进的时候,使用了错误的空格和tab 我使用的python3.5,造成这个错误的原因是我在函数里面敲if....elif 判断语句的时候,elif之前先用了空格然后再用tab完成了对齐,也就是说,这种错误产生的原因正是由于空格或者tab缩进造成的. 然后我做了试验,将空格删除,直接使用tab完成缩进,发现程序正常运行: 再试一下空格缩进,然

Python之TabError: inconsistent use of tabs and spaces in indentation和ModuleNotFoundError:No module named 'win32api'

1.TabError: inconsistent use of tabs and spaces in indentation 这是我的代码,感觉没啥不对, 后来运行之后出现了下面的错误,我也是弄了好久才弄好这个bug. . 这个一般是由于你用编译器写代码时的Tab符和空格符混用引起的.对于Notepade++来说,只要你设置"显示空格和制表符"就行. 1.点击如下按钮: 2.手动设置: View->Show Symbl->Show All Characters 下面是设置之

TabError: Inconsistent use of tabs and spaces in indentation

Pyhton 编辑错误 问题: TabError: Inconsistent use of tabs and spaces in indentation 解决方法: 这个错误是说你用了tab键作缩进了, 因为在python不像C/C++里用大括号来区分程序块,而是用缩进 所以缩进很重要你把Tab都换成空格就好了 版权声明:本文为博主原创文章,未经博主允许不得转载.

PyCharm出现TabError: inconsistent use of tabs and spaces in indentation最简单实用的解决办法

本文使用PyCharm的格式化代码功能解决TabError: inconsistent use of tabs and spaces in indentation. 当把代码从别处复制进来PyCharm,然后运行报错:TabError: inconsistent use of tabs and spaces in indentation 这个报错的意思是说IDE分不清tab和空格,说明你的代码中混用了tab和空格. 传统的方式是找出代码中报错的地方,然后修改. 这种方法可以,但是我试的并不好用.

Python文件运行时报TabError: inconsistent use of tabs and spaces in indentation

1. 问题描述 2. 问题原因 tab 和 space混合使用导致程序错误 3. 解决方案 排查出错地方的格式 原文地址:https://www.cnblogs.com/HurryXin/p/9461391.html

Python错误提示:[Errno 24] Too many open files的分析与解决

背景 最近在工作中发现了一个错误,在执行多线程扫描脚本的时候频繁出现下面这个错误 HTTPConnectionPool(host='t.tips', port=80): Max retries exceeded with url: /index.php (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f29d4081150>: Failed to e

python操作剪贴板错误提示:pywintypes.error: (1418, &#39;GetClipboardData&#39;,线程没有打开的剪贴板)

问题现象:通过打断点,一步步调试可以正常复制和粘贴剪贴板数据.但是直接运行会报错pywintypes.error: (1418, 'GetClipboardData',线程没有打开的剪贴板) 问题原因:原因是直接运行的话,没办法控制main线程的运行顺序,可能出现setText()还未关闭剪贴板,getText()就打开了剪贴板的情况. 但是打了断点之后,就可以按照代码中所写的那样的顺序来执行了. 解决方法:在调用Clipboard.setText(content)之后,一定要加time.sle

python在使用HTMLTestRunner时,报告为空,错误提示&lt;_io.TextIOWrapper name=&#39;&lt;stderr&gt;&#39; mode=&#39;w&#39; encoding=&#39;utf_8&#39;&gt;

解决方案:将HTMLTestRunner脚本的第631行的 print >> sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime) 或print(sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)) 修改为 sys.stderr.write('\nTime Elapsed: %s\n' % (self.stopTime - self.st

Python Socket TypeError: a bytes-like object is required, not &#39;str&#39; 错误提示

在学习socket编程时,遇到代码返回如下错误: TypeError: a bytes-like object is required, not 'str' 发现这里python3.5和Python2.7在套接字返回值解码上有区别. 首先可以明确,在python3中默认的编码方式是unicode.unicode 分为 utf-32(占4个字节),utf-16(占两个字节),utf-8(占1-4个字节),因此 utf-16就是现在最常用的unicode版本. 不过考虑到utf8省空间,在文件里存的