似乎没有Python 3时为什么会给出制表符错误?

时间:2019-07-03 13:40:04

标签: python-3.x tabs indentation

我正在写一个python游戏,它说空格和缩进的用法很奇怪。我不知道为什么,因为对我来说似乎完全可以。为什么不起作用?

import random
import time
from time import sleep
import sys

class Stats:
    def __init__(self, hunger, dehydration, phys_strength, mental_strength, psychic_powers, intelligence):
        self.hunger = hunger
        self.dehydration = dehydration
        self.phys_strength = phys_strength
        self.mental_strength = mental_strength
        self.psychic_powers = psychic_powers
        self.intelligence = intelligence

hero_stats = Stats(10, 10, 10, 20, 0, 20)

hunger_info = f"Your hunger level is {hero_stats.hunger}. Your stomach is full when you are at 0, and you starve at 100."


def user_input(input1):
    if input1.lower() == "hunger info":
        printfast("\n")
        printfast(hunger_info)

错误:

Python Files xxxxxxxxxxxxxx$ python3 adventuregame.py
  File "adventuregame.py", line 36
    printfast(hunger_info)
                         ^
TabError: inconsistent use of tabs and spaces in indentation
xxxxxxx-Air:Python Files xxxxxxxxxxxxxx$

1 个答案:

答案 0 :(得分:0)

在上一行printfast("\n")的前面有一个制表符,而其余缩进已用空格完成。

您应该始终使用将制表符转换为4个空格的编辑器。