An operational explanation of Python metaclasses (part 2)After modifying a class as it's being created (covered in part 1), the next thing you can do with a metaclass is
get a chance to do things when instances of the class are created.
You do this by defining
class MiniMeta(type):
def __call__(cls, *args, **kwargs):
return super(MiniMeta, cls).\
__call__(*args, **kwargs)
class Example(object):
__metaclass__ = MiniMeta
There are a number of things that you can do with this. One of them
(which I first saw in another metaclass tutorial) is handling deferred
initialization and setup of something related to the class. Rather than
doing this in your metaclass Using a metaclass (This use of metaclasses is considered sufficiently interested to
get mentioned in passing in the official documentation for
PS: Sidebar: a technicalityStrictly speaking using |
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |