当把代码从别处复制进来PyCharm,然后运行报错:TabError: inconsistent use of tabs and spaces in indentation

这个报错的意思是说IDE分不清tab和空格,说明你的代码中混用了tab和空格。

解决的方法有:

方法一. 找出所有的空格和tab

首先 File -> Settings -> Editor -> General -> Appearance -> Show whitespaces,如图所示:
PyCharm中解决TabError: inconsistent use of tabs and spaces in indentation
File -> Default Settings -> Editor -> Code Style -> Python -> 在Tabs and Indents选项卡中,勾选“Use tab character”

之后再代码中就会显示出Tab为一个箭头,而空格的话就会显示为比较小的点
PyCharm中解决TabError: inconsistent use of tabs and spaces in indentation

方法二:格式化代码!

具体操作是:Code -->Reformat Code

PyCharm中解决TabError: inconsistent use of tabs and spaces in indentation

再次尝试运行即可!

参考文章:https://www.cnblogs.com/sgh1023/p/10013071.html

相关文章:

  • 2021-06-15
  • 2021-08-17
  • 2021-09-06
  • 2021-09-12
  • 2021-11-22
  • 2021-06-13
  • 2021-07-12
  • 2021-07-10
猜你喜欢
  • 2021-10-02
  • 2022-01-13
  • 2021-06-04
  • 2021-06-04
  • 2021-05-06
相关资源
相似解决方案