Are there some way to use the class attribute from parent inside child but do not inherit it?
class CycleFactory:
all_cycles = [202015, 202016, 202017, 202101]
class Cycle(int, CycleFactory):
def __init__(self, cycle):
self.cycle = cycle
def __add__(self, other):
return self.all_cycles[self.all_cycles.index(self.cycle) + other]
def __sub__(self, other):
return self.all_cycles[self.all_cycles.index(self.cycle) - other]
This is the example code. The point is that I'll create many instances of Cycle
class and it's running out of memory because the all_cycles
attribute has much more items than the example, but it's fixed to all instances of Cycle
.
How could I achieve this? Use just one fixed attribute on a parent class to do not recreate it every time when I use the child class?
I thought about using the Factory and Abstract factory patterns, but they are not related to attributes, only creating new objects using a class Factory.