问题描述
这是茶:我正在使用 python 编写一个小型大富翁游戏。我让这个小家庭来代表账单。有一个名为 Bill 的基 abstract class
,它继承自 abc.ABC
类。
代码:
from abc import ABC,abstractmethod
import colorama
colorama.init(autoreset=True,strip=True)
class Bill(ABC):
#Abstract Properties (must be overriden in subclasses)
@property
@abstractmethod
def count(self):
return 0
@property
@abstractmethod
def color(self): # colorama background color
return 0
@property
@abstractmethod
def worth(self): # integer representing the bill's worth
return 0
# Dunder methods (The same across class family)
def __add__(self,other):
return self.worth + other.worth
def __str__(self):
return f" {self.color} {self.worth}"
class One(Bill):
def __init__(self):
self.__count = 0
self.__color = "\033[0m"
self.__worth = 0
#super().init() ??
# Override Abstract Methods
@property
def count(self):
return self.__count
@count.setter
def count(self,amount):
self.__count += 1
@property
def worth(self):
return 1
@property
def color(self):
return colorama.Back.WHITE
我的问题是我的子类是否会继承 Bill
类的 dunder 方法。
如果没有,我是否需要在 super().__init__()
类的 One
方法中包含 __init__
?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)