0

I don't understand why i'm getting an indentation error with that type of code. My function is inside a class and the indentation is "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

The error come at this precise line.

PoidBarriere1 = self.shakers[NumShaker, 14]
EzLo
  • 13,780
  • 10
  • 33
  • 38
Cheen
  • 86
  • 3
  • 12
  • 2
    Can you post the `exception` that you are facing? – bumblebee Apr 30 '19 at 10:04
  • 1
    copy paste the code that you wrote here. replace/override the older code. The function written here seems to get defined just fine. – Paritosh Singh Apr 30 '19 at 10:04
  • Please refer to this https://stackoverflow.com/questions/14979224/indentation-error-in-python – bumblebee Apr 30 '19 at 10:05
  • what text editor are you using ? You should use 4 spaces instead of tabs. You can convert all tabs to spaces. –  Apr 30 '19 at 10:05
  • I'm using SublimeText and i copied-past and doesn't work – Cheen Apr 30 '19 at 10:09
  • It's possible that tabs and spaces got mixed up in your code. Which could happen when copying code for example. Depending on the editor you're using you can convert your tabs to spaces automatically. – funie200 Apr 30 '19 at 10:12
  • Looking at the sourse of your question, you are mixing tabs and spaces. The line `PoidBarriere1 = ...` has 4 spaces, then 1 tab. The lines before that have 8 spaces. (including the spaces to indent the code block) – tobias_k Apr 30 '19 at 11:23
  • Thank you tobias_k that was the problem – Cheen Apr 30 '19 at 12:13

2 Answers2

0

Code looks fine to me. Maybe there is a tab instead of spaces?

3UqU57GnaX
  • 389
  • 3
  • 12
0

Python expects indentation to be consistent, tabs and spaces may be treated differently.

If you have copied some code the spacing may be different. Try the settings in your editor and enable the 'convert tabs to spaces' feature this will remove ambiguity between tabs and spaces by replacing tabs with a number of spaces.

StackyChan
  • 41
  • 1
  • Yes tabs and 4 spaces isn't making any difference (in the other parts of my code, i used both and its working). If i delete lines 2 to 5, it's working (I added that part after so maybe there is a problem but.. Where and why) – Cheen Apr 30 '19 at 12:10