无法使用抽象方法getAdminCharge、getFinesPerDay实例化抽象类项。不能的

2024-05-19 11:03:18 发布

您现在位置:Python中文网/ 问答频道 /正文

from abc import ABC, abstractmethod
import datetime
from typing import List

class Item(ABC):
    _loanDuration = 14    

    @classmethod
    def getLoanDuration(cls):
        return cls._loanDuration
    
    @classmethod
    def setLoanDuration(cls, newDuration):
        cls._loanDuration = newDuration

    def __init__(self, title: str, yearPublished: int, cost: float):
        self._title = title
        self._yearPublished = yearPublished
        self._cost = cost

    @property
    def title(self):
        return self._title

    @property
    def yearPublished(self):
        return self._yearPublished

    @property
    def cost(self):
        return self._cost

    @abstractmethod
    def getAdminCharge(self):
        return self.getAdminCharge
    
    @abstractmethod
    def getFinesPerDay(self):
        return self.getAdminCharge
    
    def lostCharges(self):
        return self.getAdminCharge() + self._cost

    def __str__(self):
        return f"{self._title} {self._yearPublished} Cost: ${self._cost}"
    
C1 = Item("Asia Food And Culture","2019","30")
    
print(C1)

Tags: fromimportselfreturntitledefpropertyitem

热门问题