没有缩进错误时的Python缩进错误 [英] Python Indentation Error when there is no indent error

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

问题描述

是我还是翻译?我在代码中没有看到缩进错误,但是它一直告诉我有错误!我使用自动缩进,所以应该没问题.每当出现缩进错误时,我都会退格然后再次缩进,这似乎可以解决它,因为缩进错误不再在该行上,而是在另一行上.有人可以告诉我怎么了

Is it me or the interpreter? I see no indentation error in my code but it kept telling me that there is an error! I use auto indentation so it should be ok. When ever there is an indentation error, I backspace then indent again and it seems to fix it because the indentation error is not on that line anymore but on the other line. Can someone please tell me what is wrong

class LogicGate:
    def __init__(self,n):
        self.label = n
        self.output = None

    def getLabel(self):
        return self.label

    def getOutput(self):
        self.output = self.performGateLogic()
        return self.output

自我回答:我的IDE的自动缩进是使用tab缩进的,有时当我退格时,我会再次使用空格缩进.因此,问题在于混合了空格和制表符.我建议将您的IDE设置为缩进或不使用制表符.参见 https://www.python.org/dev/peps/

Self answer: the auto indentation of my IDE is indent with tab, and sometimes when I back space I indent it with spaces again. So the problem is mixing spaces and tabs. I recommend setting your IDE to indent with spaces or don't use tabs. See https://www.python.org/dev/peps/

推荐答案

您的制表符和空格必须混在一起.将编辑器的选项卡设置为4个空格.您还可以在编辑器上打开空白指示器,这有助于解决缩进错误.

Your tabs and spaces must be getting mixed up. Set you editor to 4 spaces for a tab. You can also turn on whitespace indicator on the editor, which can help resolving the indentation errors.

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

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