spam (,{'data' 'meth''__module__''__main__'making instance data presentation notei' truncating addresses and omitting some irrelevant built-in __x__ names in namespace dictionaries in this for brevityand as noted earlier am forgoing portability due to differing declaration syntax to run in xuse the class attribute formand change print operations as desired this example works in with the following modificationsin the file metaclass - pynotice that either eggs or spam must be derived from object explicitlyor else issues warning because new-style class can' have only classic bases here--when in doubtuse object in metaclasses clientsto run the same in (onlyone of the "objectoptional from __future__ import print_function class eggs(object)class spam(eggsobject)__metaclass__ metaone customizing construction and initialization metaclasses can also tap into the __init__ protocol invoked by the type object' __call__ in general__new__ creates and returns the class objectand __init__ initializes the already created class passed in as an argument metaclasses can use either or both hooks to manage the class at creation timeclass metatwo(type)def __new__(metaclassnamesupersclassdict)print('in metatwo new'classnamesupersclassdictsep='\ 'return type __new__(metaclassnamesupersclassdictdef __init__(classclassnamesupersclassdict)print('in metatwo init:'classnamesupersclassdictsep='\ 'print(init class object:'list(class __dict__ keys())class eggspass print('making class'class spam(eggsmetaclass=metatwo)data def meth(selfarg)return self data arg inherits from eggsinstance of metatwo class data attribute class method attribute print('making instance' spam(print('data:' datax meth( )in this casethe class initialization method is run after the class construction methodbut both run at the end of the class statement before any instances are made con metaclasses