0

I noticed many built-in classes do not have a __dict__ and even classes in modules such as numpy do not have __dict__ defined as they had been defined in C.

I want to define __getattr__, but I'm worried about a recursive loop creeping into the (long) code of one of my class (e.g. see the second reply Understanding the difference between __getattr__ and __getattribute__).

Is there a way I can disable creation of __dict__? Do I need to use __slots__ ?

Community
  • 1
  • 1
uday
  • 6,053
  • 13
  • 52
  • 90

1 Answers1

0

Not having a __dict__ will not prevent you from writing an infinite recursive loop.

And yes, defining __slots__ will prevent the creation of a __dict__.

Ethan Furman
  • 57,917
  • 18
  • 142
  • 218