Python:Taberror

时间:2018-06-29 22:53:24

标签: python python-3.x syntax indentation

我有一个爱沙尼亚语脚本,但它给我错误:

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

,代码为:

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")

找不到问题-尝试删除并重试,但没有任何变化

1 个答案:

答案 0 :(得分:1)

标准化您的源代码。根据{{​​3}}“在每个缩进级别使用4个空格”。您提到,如果您在一个缩进上下文(例如函数)中混合使用制表符和空格,则会收到警告。

以下源代码格式错误(<SPACE>代表空格字符,<TAB>代表水平制表符):

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

将出现以下错误:

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

以下程序正确:

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

顺便说一句,while end == False应该写为while not end,并在下一行中要求附加缩进级别。