Rauno Ehasalu
Rauno Ehasalu

Reputation: 25

Python : Taberror

I have one Estonian script, but It gives me error:

    Sorry: TabError: inconsistent use of tabs and spaces in indentation (function sheet1.py, line 8)
[Finished in 0.2s with exit code 1]

and code is:

import sys
import datetime
end = False
while end == False:
def contin01():
    print("Kas soovid jätkata?")
    exit = input("Vali [1] - JAH // Vali [2] - EI: ")
    if exit[0] == "1":
        print("********* Beginning of Line ********* ")
    elif exit[0] == "2":
        sys.exit()
def sina():
    nimi = input("Kirjuta enda nimi: ")
def guest_name():
    Guest_Name = input("Sisesta kliendi nimi: ")
def guest_arrival():
    Arrival = input("Sisesta kliendi saabumiskuupäev: ")
def guest_dep():
    Departure = input("Sisesta kliendi lahkumiskuupäev: ")
def room():
    Room_number = input("Sisesta kliendi toa number ")
def special():
    req = input("Kirjuta kliendi erisoovid, kui puuduvad pane "-": ")
def WU():
    wake = input("Kirjuta mis kell soovib klient äratust")
def date():
    päev = datetime.datetime.now().strftime("%d-%m-%Y T%H:%M")

can't find the problem - tried deleting and trying again but nothing changes

Upvotes: 0

Views: 303

Answers (1)

meisterluk
meisterluk

Reputation: 824

Normalize your source code. "Use 4 spaces per indentation level" according to Python PEP8. If you mix tabs and space within one indentation context (e.g. function), you will get the warning, you mentioned.

The following source code is badly formatted (where <SPACE> stands for a space character and <TAB> stands for the horizontal tab):

def func(x):
<SPACE><SPACE><SPACE><SPACE>if x == 6:
<TAB><TAB>return 1
<SPACE><SPACE><SPACE><SPACE>return 42

will give the following error:

  File "test.py", line 3
    return 1
           ^
TabError: inconsistent use of tabs and spaces in indentation

whereas the following program is correct:

def func(x):
<SPACE><SPACE><SPACE><SPACE>if x == 6:
<SPACE><SPACE><SPACE><SPACE><SPACE><SPACE><SPACE><SPACE>return 1
<SPACE><SPACE><SPACE><SPACE>return 42

BTW, while end == False should be written while not end and requires an additional indentation level in the following line.

Upvotes: 1

Related Questions