appendix python result this dictionary is what gets populated as the body of the class definition executes here is an example that outlines the basic procedureclass mymeta(type)@classmethod def _prepare_ (cls,name,bases,**kwargs)print("preparing",name,bases,kwargsreturn {def _new_ (cls,name,bases,classdict)print("creating",name,bases,classdictreturn type _new_ (cls,name,bases,classdictpython uses an alternative syntax for specifying metaclass for exampleto define class that uses mymetayou use thisclass foo(metaclass=mymeta)print("about to define methods"def _init_ (self)pass def bar(self)pass print("done defining methods"if you run the following codeyou will see the following output that illustrates the control flowpreparing foo ({about to define methods done defining methods creating foo ({' _module_ '' _main_ ''bar'' _init_ 'the additional keyword arguments on the _prepare_ (method of the metaclass are passed from keyword arguments used in the bases list of class statement for examplethe statement class foo(metaclass=mymeta,spam= ,blah="hello"passes the keyword arguments spam and blah to mymeta _prepare_ (this convention can be used to pass arbitrary configuration information to metaclass to perform any kind of useful processing with the new _prepare_ (method of metaclassesyou generally have the method return customized dictionary object for exampleif you wanted to perform special processing as class is definedyou define class that inherits from dict and reimplements the _setitem_ (method to capture assignments to the class dictionary the following example illustrates this by defining metaclass that reports errors if any method or class variable is multiply defined class multipledef(dict)def _init_ (self)self multipleset(def _setitem_ (self,name,value)if name in selfself multiple add(namedict _setitem_ (self,name,valueclass multimeta(type)@classmethod def _prepare_ (cls,name,bases,**kwargs)return multipledef(def _new_ (cls,name,bases,classdict)for name in classdict multipleprint(name,"multiply defined" lib fl ff