What is a metaclass in Python?

PythonServer Side ProgrammingProgramming

A metaclass is a class which has classes as its instances. Like an "ordinary" class defines the behavior of the instances of the class, a metaclass also defines the behavior of its classes and their instances.

Metaclasses are supported by Python. Some programmers consider metaclasses in Python as "solutions waiting or looking for a problem".

There are numerous applications of metaclasses. Few of them are −

  • logging and profiling;

  • interface checking;

  • registering classes at creation time;

  • automatically adding new methods;

  • automatic property creation;

  • proxies etc.

raja
Published on 22-Jan-2018 06:32:33
Advertisements