静态方法导致意外缩进错误?

时间:2021-04-29 04:54:20

标签: python python-3.x error-handling indentation

出于某种原因,当我运行此代码时,我在 @staticmethod 行上遇到了意外的缩进错误,但我不知道为什么!一切都正确缩进,但这导致我的所有方法在代码发布中引发错误。此外,我从类中删除了一些其他方法以缩短我在此处发布的代码。

class Reservation:
    """A data type that represents a hotel room booking system."""
    booking_numbers = []

    @staticmethod
    def get_reservations_from_row(room_obj, list_tuples):
    
        reservation_dict = {}
        booking_num_list = []
        date_list = []
        for element in list_tuples:
            year, month, day, short_str = element
            list_short_str = short_str.split('--')
            booking_num = int(list_short_str[0])
            name = list_short_str[1]
        
            if booking_num not in booking_num_list:
                booking_num_list.append(booking_num)
      
            date = datetime.date(year, month, day)
        
            date_list.append(date)
         
        for element in booking_num_list:
            print(date_list)
            date_list.sort()
            value = Reservation(name, room_obj, date_list[0], date_list[len(date_list)-1], element)
    
            reservation_dict[element] = reservation_dict.get(element, []) + value
        return reservation_dict

回溯(最近一次调用最后一次): 文件“/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py”,第 35 行,解析 返回编译(源,文件名,模式,PyCF_ONLY_AST) 文件“/Users/myname/Downloads/reservation.py”,第 74 行 @静态方法 ^ 缩进错误:意外缩进

1 个答案:

答案 0 :(得分:0)

您似乎使用了 tab 进行缩进。 删除标签并插入 4 空格,它对您有用