自动更正Python中的缩进错误 [英] Auto correct indentation errors in Python

查看:81
本文介绍了自动更正Python中的缩进错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修复Python脚本中的某些缩进错误.有没有一种方法可以在线或使用其他实用程序自动更正错误?

I am trying fix some indentation errors in a Python script. Is there a way to auto correct the errors online or using other utilities?

我希望这个错误是非常熟悉的,但想再次避免.有任何编辑者可以帮助解决这些问题吗?

I hope this error is very familiar, but wanted to avoid this again. Does any editor help in fixing these issues?

IndentationError:预期为缩进的块

IndentationError: expected an indented block

推荐答案

一般来说是不可能的,因为在某些情况下模棱两可:

It's not possible in general because some cases would be ambiguous:

something = foo()
if something:
    something.bar()
  print("ok") # Only half indented. Should this be inside or outside of the if statement?

最好找到一个具有自动缩进支持的编辑器,并确保您缩进正确(即使是在没有大量空格的语言中,因为这样会使您的代码更易于阅读).

It's much better to find an editor with auto-indentation support and make sure you indent properly (even in languages without significant whitespaces, as it makes your code easier to read).

这篇关于自动更正Python中的缩进错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆