TypeError : 'Aircraft'개체를 호출 할 수 없습니다.

요한 버저

Python 자습서에서 작업 중이며 TypeError : 'Aircraft'개체가 호출 가능하지 않습니다.

다음은 전체 오류 메시지입니다.

    Traceback (most recent call last):
      File "/usr/lib/python3.4/code.py", line 90, in runcode
        exec(code, self.locals)
      File "<input>", line 1, in <module>
      File "/home/johanvergeer/Documenten/Training/Pluralsight/Python-              Fundamentals/airtravel.py", line 29, in aircraft
        return self._aircraft()
    TypeError: 'Aircraft' object is not callable

그리고 이것은 내가 작업중 인 Python 코드입니다.

class Flight:
    """A flight with a particular passenger aircraft"""

    def __init__(self, number, aircraft):
        if not number[:2].isalpha():
            raise ValueError("No airline code in '{}'".format(number))
        if not number[:2].isupper():
            raise ValueError("Invalid airline code '{}'".format(number))
        if not (number[2:].isdigit() and 4 >= len(number[2:]) >= 3):
            raise ValueError("Invalid route number '{}'".format(number))
        self._number = number
        self._aircraft = aircraft

        rows, seats = self._aircraft.seating_plan()
        self._seating = [None] + [{letter: None for letter in seats} for _ in
                                  rows]

    def number(self):
        return self._number

    def airline(self):
        return self._number[:2]

    def aircraft(self):
        return self._aircraft()

    def _parse_seat(self, seat):
        """Parse a seat designator into a valid row and letter.

        Args:
            seat: a seat designator such as 12F.

        Returns:
            A tuple containing an integer and a string for row and seat.
        """
        row_numbers, seat_letters = self._aircraft.seating_plan()

        letter = seat[-1]
        if letter not in seat_letters:
            raise ValueError("Invalid seat letter {}".format(letter))

        row_text = seat[:-1]
        try:
            row = int(row_text)
        except ValueError:
            raise ValueError("Invalid seat row {}".format(row_text))

        if row not in row_numbers:
            raise ValueError("Invalid row number {}".format(row))
        return row, letter

    def allocate_seat(self, seat, passenger):
        """Allocate a seat to a passenger.

        Args:
            seat: A seat designator such as '12C' or '21F'.
            passenger: The passenger name.

        Raises:
            ValueError: If the seat is unavailable.
        """

        row, letter = self._parse_seat(seat)

        if self._seating[row][letter] is not None:
            raise ValueError("Seat {} already occupied".format(seat))

        self._seating[row][letter] = passenger

    def relocate_passenger(self, from_seat, to_seat):
        """Relocate a passenger to a different seat.

        Args:
            from_seat: The existing seat assigned to the passenger to be moved.
            to_seat: The new seat designator.
        """

        from_row, from_letter = self._parse_seat(from_seat)

        if self._seating[from_row][from_letter] is None:
            raise ValueError(
                "No passenger to relocate in seat {}".format(from_seat))

        to_row, to_letter = self._parse_seat(to_seat)

        if self._seating[to_row][to_letter] is not None:
            raise ValueError("Seat {} is already occupied".format(to_seat))

        self._seating[to_row][to_letter] = self._seating[from_row][from_letter]
        self._seating[from_row][from_letter] = None

    def num_available_seats(self):
        return sum(sum(1 for s in row.values() if s is None)
                   for row in self._seating
                   if row is not None)

    def make_boarding_cards(self, card_printer):
        for passenger, seat in sorted(self._passenger_seats()):
            card_printer(passenger, seat, self.number(), self.aircraft())

    def _passenger_seats(self):
        """ An iterable series of passenger seating allocations"""
        row_numbers, seat_letters = self._aircraft.seating_plan()
        for row in row_numbers:
            for letter in seat_letters:
                passenger = self._seating[row][letter]
                if passenger is not None:
                    yield (passenger, "{}{}".format(row, letter))


class Aircraft:
    def __init__(self, registration, model, num_rows, num_seats_per_row):
        self._registration = registration
        self._model = model
        self._num_rows = num_rows
        self._num_seat_per_row = num_seats_per_row

    def registration(self):
        return self._registration

    def model(self):
        return self._model

    def seating_plan(self):
        return (range(1, self._num_rows + 1),
                "ABCDEFGHJK"[:self._num_seat_per_row])


def make_flight():
    f = Flight("BA758", Aircraft("G-EUPT", "Airbus A319", num_rows=22,
                                 num_seats_per_row=6))
    f.allocate_seat("12A", "Guido van Rossum")
    f.allocate_seat("15F", "Bjorne Stroustrup")
    f.allocate_seat("15E", "Anders Hejlsberg")
    f.allocate_seat("1C", "John McCarthy")
    f.allocate_seat("1D", "Richard Hickey")
    return f


def console_card_printer(passenger, seat, flight_number, aircraft):
    output = "| Name : {0}" \
             "  Flight : {1}" \
             "  Seat: {2}" \
             "  Aircraft : {4}" \
             "  |".format(passenger, flight_number, seat, aircraft)
    banner = "+" + "-" * (len(output) - 2) + "+"
    border = "|" + " " * (len(output) - 2) + "|"
    lines = [banner, border, output, border, banner]
    card = "\n".join(lines)
    print(card)
    print()

누군가가 나를 도울 수 있다면 나는 매우 좋을 것입니다.

요사 리안

문제는 여기에 있습니다 Flight.

def aircraft(self):
    return self._aircraft()

self._aircraft()self._aircraft유형의 객체 일 때 함수 로 사용하려고 합니다 Aircraft. Flight.aircraft방법을 다음으로 변경하십시오.

def aircraft(self):
    return self._aircraft

이것은 실제 개체를 반환합니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

TypeError : '_IncompatibleKeys'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'NoneType'개체는 CircleCI를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'CurrencyConverter'개체를 호출 할 수 없습니다.

분류에서Dev

firebase = firebase (config) TypeError : 'module'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

분류에서Dev

TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

분류에서Dev

Q : TypeError : '_csv.reader'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Int64Index'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Player'개체는 Django를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Post'개체를 호출 할 수 없습니다.

분류에서Dev

groupby-TypeError 'DataFrame'개체를 호출 할 수 없습니다.

분류에서Dev

Python Script TypeError : 'int'개체를 호출 할 수 없습니다.

분류에서Dev

Python 오류 : TypeError : 'list'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : '게임'개체를 호출 할 수 없습니다.

분류에서Dev

Python / Pygame : TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

Python-TypeError : 'list'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Weather'개체를 호출 할 수 없습니다.

분류에서Dev

Python TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

django-selenium TypeError : 'str'개체를 호출 할 수 없습니다.

분류에서Dev

Python setter TypeError : 'int'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : print를 호출 할 때 'str'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 스크래핑 할 때 'NoneType'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'numpy.float64'개체를 호출 할 수 없습니까?

분류에서Dev

TypeError : 'str'개체는 MySQL에서 호출 할 수 없습니다.

분류에서Dev

'모듈'개체의 TypeError는 호출 할 수 없습니다.

분류에서Dev

TypeError at / 'SimpleLazyObject'개체는 호출 할 수 없습니다.

분류에서Dev

Python timeit-TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

Pytorch 1.7.0 | DataLoader 오류-TypeError : '모듈'개체를 호출 할 수 없습니다.

Related 관련 기사

  1. 1

    TypeError : '_IncompatibleKeys'개체를 호출 할 수 없습니다.

  2. 2

    TypeError : 'NoneType'개체는 CircleCI를 호출 할 수 없습니다.

  3. 3

    TypeError : 'CurrencyConverter'개체를 호출 할 수 없습니다.

  4. 4

    firebase = firebase (config) TypeError : 'module'개체를 호출 할 수 없습니다.

  5. 5

    TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

  6. 6

    TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

  7. 7

    Q : TypeError : '_csv.reader'개체를 호출 할 수 없습니다.

  8. 8

    TypeError : 'Int64Index'개체를 호출 할 수 없습니다.

  9. 9

    TypeError : 'Player'개체는 Django를 호출 할 수 없습니다.

  10. 10

    TypeError : 'Post'개체를 호출 할 수 없습니다.

  11. 11

    groupby-TypeError 'DataFrame'개체를 호출 할 수 없습니다.

  12. 12

    Python Script TypeError : 'int'개체를 호출 할 수 없습니다.

  13. 13

    Python 오류 : TypeError : 'list'개체를 호출 할 수 없습니다.

  14. 14

    TypeError : '게임'개체를 호출 할 수 없습니다.

  15. 15

    Python / Pygame : TypeError : '모듈'개체를 호출 할 수 없습니다.

  16. 16

    Python-TypeError : 'list'개체를 호출 할 수 없습니다.

  17. 17

    TypeError : 'Weather'개체를 호출 할 수 없습니다.

  18. 18

    Python TypeError : '모듈'개체를 호출 할 수 없습니다.

  19. 19

    TypeError '모듈'개체를 호출 할 수 없습니다.

  20. 20

    django-selenium TypeError : 'str'개체를 호출 할 수 없습니다.

  21. 21

    Python setter TypeError : 'int'개체를 호출 할 수 없습니다.

  22. 22

    TypeError : print를 호출 할 때 'str'개체를 호출 할 수 없습니다.

  23. 23

    TypeError : 스크래핑 할 때 'NoneType'개체를 호출 할 수 없습니다.

  24. 24

    TypeError : 'numpy.float64'개체를 호출 할 수 없습니까?

  25. 25

    TypeError : 'str'개체는 MySQL에서 호출 할 수 없습니다.

  26. 26

    '모듈'개체의 TypeError는 호출 할 수 없습니다.

  27. 27

    TypeError at / 'SimpleLazyObject'개체는 호출 할 수 없습니다.

  28. 28

    Python timeit-TypeError : '모듈'개체를 호출 할 수 없습니다.

  29. 29

    Pytorch 1.7.0 | DataLoader 오류-TypeError : '모듈'개체를 호출 할 수 없습니다.

뜨겁다태그

보관