缩进 Python

Indentation with Python

我不明白为什么我在使用那种类型的代码时会出现缩进错误。我的函数在 class 内,缩进是 "normal".

def SelectBarriere(self, NumShaker, B_Bar1, B_Bar2, B_Bar3):
    self.Lab_IMV = Label(self, "Configuration IMV:")
    self.Lab_IMV.move(1000, 250)
    self.BarIMVacc = BarPourcentage(self)
    self.BarIMVacc.move(1000,290)
    PoidBarriere1 = self.shakers[NumShaker, 14]
    PoidBarriere2 = self.shakers[NumShaker, 15]
    PoidBarriere3 = self.shakers[NumShaker, 16]
    if B_Bar1 == 2:
        self.MasseThermique = PoidBarriere1
    elif B_Bar2 == 2:
        self.MasseThermique = PoidBarriere2
    elif B_Bar3 == 2:
        self.MasseThermique = PoidBarriere3
    else:
        self.MasseThermique = 0
    return self.MasseThermique

错误出现在这一行。

PoidBarriere1 = self.shakers[NumShaker, 14]

我觉得代码不错。也许有制表符而不是空格?

Python 期望缩进保持一致,制表符和空格可能会被区别对待。

如果您复制了一些代码,间距可能会有所不同。在您的编辑器中尝试设置并启用 'convert tabs to spaces' 功能,这将通过用多个空格替换制表符来消除制表符和空格之间的歧义。