Category : oop

Let’s say I have these two classes: class Order: def __init__(self, dish, status): self.dish = dish self.status = status def cook(self): self.status = ‘cooking’ def serve(self): self.status = ‘served’ and class Orders: def __init__(self, all_orders): self.lst = all_orders self.waiting = [o for o in self.lst if o.status==’waiting’] self.cooking = [o for o in self.lst if ..

Read more

Let’s say I have these two classes: class Ball: def __init__(self, shape): self.shape = shape and class Balls: def __init__(self, *args): self.rounds = [b for b in args if b.shape==’round’] self.ovals = [b for b in args if b.shape==’oval’] The problem is, after I’ve called something like balls = Balls(Ball(’round’), Ball(’round’), Ball(‘oval’)), each ball in ..

Read more

I have a problem, I enum with several types of certain object class Type(Enum): TYPE_A TYPE_B TYPE_C TYPE_D …. class Something(): def __init__(self): self.TYPE_A_list = [] self.TYPE_B_list = [] self.TYPE_C_list = [] self.TYPE_D_list = [] … def add_data(self, type: Type, value: int): if type == TYPE_A: self.TYPE_A_list.append(value) elif type == TYPE_B: self.TYPE_A_list.append(value) elif type == ..

Read more

I have a text file with a list of car types, for example: Ferrari Volvo Audi Tesla In my code I have the following structure class Car(ABC): … @abstractmethod def refuel(self): pass class Ferrari(Car): … def refuel(self): print(‘Refueling a Ferrari’) class Tesla(Car): … def refuel(self): print(‘Refueling a Tesla’) … I want to parse the text ..

Read more