0

I have a class that takes a dict and initialize constructors to set the class members. I am new to Python Object Oriented and I read about __slots__ attributes from here and am wondering if I need to declare __slots__ for my sample class below? If not, what is the best and most pythonic way here?

class MyClass:
    __slots__: List[str] = ["tmp_dict"]
    def __init__(self, tmp_dict):
        self.tmp_dict = tmp_dict
armin
  • 591
  • 3
  • 10
  • `__slots__` is purely a technique for reducing the memory footprint of your objects. It's not something you should normally bother with unless you expect millions of instances of your class to exist simultaneously. – jasonharper May 11 '21 at 16:48
  • you dont need to declare `__slots__` for your class. "Pythonic" on its own does not really mean anything, to quote someone: No single word has done as much damage to the Python ecosystem as “Pythonic.” It’s the ultimate tool to discredit any kind of work based on knee jerk reactions with no recourse because it’s 100% subjective. – yedpodtrzitko May 11 '21 at 16:49

0 Answers0