Category : design-patterns

I am trying to keep a registry of the concrete classes that implements my abstract class. So, i can instantiate objects using a factory method. Here is my code example: from abc import ABC, abstractmethod class AbstractReductor(ABC): _registry = {} def __init_subclass__(cls, **kwargs): super().__init_subclass__() cls.register_reductor(cls) def __init__(self, name, config): self._name = name self._config = config ..

Read more

Consider the following (very simplified) project structure: project/ src/ collections/ validators/ foo/ bar/ The "collections" sub-directory name shadows the Python’s "collections" module. The "validators" sub-directory name shadows "validators" 3rd-party package name. Question: Is it an anti-pattern to have sub-directories with the same names as Python modules or 3rd-party packages? Note, the real project structure has ..

Read more

Beginner to Programming My code is below , the spaces within diamond is shown with ‘B’ and spaces outside diamond are shown with X. n=5 for i in range(n): for j in range(n,i,-1): if j==i+1: print(‘*’,end=”) break print(‘X’,end=”) for j in range(i): print(‘B’,end=”) for j in range(i+1): if i==0: continue if j==i-1: print(‘*’,end=”) break print(‘B’,end=”) ..

Read more