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


在用 Github 一个开源库 ruptures 做突变点检测时,调用它的 display 方法可视化检测结果时,觉得效果一般,如下所示:


找到 display 的源码分析,改造它的 matplotlib 绘图部分:


改进绘制折线图的线条颜色,刻度的字体为 Times New Roman 和调整大小。

保存后,执行 Python 脚本时遇到:TabError: inconsistent use of tabs and spaces in indentation,意思是不要混合使用 4 个空格和 tab 键

解决的方法:

  • Sublime Text里设置:Preferences -> Settings,设置显示制表符:“draw_white_space”: “all”
  • 以及设置 tab 键自动转化为四个空格,如下所示:
"tab_size": 4,
"translate_tabs_to_spaces": true,
"expand_tabs_on_save": true

然后重启 jupyter notebook 后再执行代码就不会报错啦。


博客园 | 解决TabError: inconsistent use of tabs and spaces in indentation

猜你喜欢

转载自blog.csdn.net/fyfugoyfa/article/details/123755242