hook to automatically augment the classes with instance counters and any other data requireddef count(aclass)aclass numinstances return aclass return class itselfinstead of wrapper @count class spamsame as spam count(spam@count class sub(spam)numinstances not needed here @count class other(spam)in factas codedthis decorator can be applied to class or functions--it happily returns the object being defined in either context after initializing the object' attribute@count def spam()pass like spam count(spam@count class otherpass like other count(otherspam numinstances other numinstances both are set to zero though this decorator manages function or class itselfas we'll see later in this bookclass decorators can also manage an object' entire interface by intercepting construction callsand wrapping the new instance object in proxy that deploys attribute accessor tools to intercept later requests-- multilevel coding technique we'll use to implement class attribute privacy in here' preview of the modeldef decorator(cls)on decoration class proxydef __init__(self*args)on instance creationmake cls self wrapped cls(*argsdef __getattr__(selfname)on attribute fetchextra ops here return getattr(self wrappednamereturn proxy @decorator class cx (like decorator(cmakes proxy that wraps cand catches later attr metaclassesmentioned briefly earlierare similarly advanced class-based tool whose roles often intersect with those of class decorators they provide an alternate modelwhich routes the creation of class object to subclass of the top-level type classat the conclusion of class statementclass meta(type)def __new__(metaclassnamesupersclassdict)extra logic class creation via type call decorators and metaclassespart