0

I have a class A with many static methods (a, b, c...z):

class A:
  @staticmethod
  def a():
    return 1
  ...

I would like to also have a "catch all" magic method such that when I call a property of A that doesn't exist, and perform some function.


I tried:

@staticmethod
def __getattr__(cls, item):
  raise Exception("fallback")

and

def fallback(cls, item):
  raise Exception("fallback")

A.__getattr__ = fallback

But when I try to access, for example A.aa, I get an error:

AttributeError: type object 'A' has no attribute 'aa'

Amit
  • 5,924
  • 7
  • 46
  • 94

0 Answers0