Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectivestype is actually ametaclass -- a class that creates another classes.Mostmetaclass are the subclasses oftype. Themetaclass receives thenew class as its first argument and provide access to class object with details as mentioned below:
>>> class MetaClass(type):... def __init__(cls, name, bases, attrs):... print ('class name: %s' %name )... print ('Defining class %s' %cls)... print('Bases %s: ' %bases)... print('Attributes')... for (name, value) in attrs.items():... print ('%s :%r' %(name, value))... >>> class NewClass(object, metaclass=MetaClass):... get_choch='dairy'... class name: NewClassBases <class 'object'>: Defining class <class 'NewClass'>get_choch :'dairy'__module__ :'builtins'__qualname__ :'NewClass'Note:
Notice that the class was not instantiated at any time; the simple act of creating the class triggered execution of themetaclass.