metaclass ???

BruceKL WhoH BruceWhoHKL at gawab.com
Wed Aug 18 04:23:33 EDT 2004


Hi,
     I have just read David Mertz's Metaclass programming in Python,but I'm still confused.
can someone show me an example to explain when metaclass is needed?
     I think metaclass can be treated as a class factory,but how to specify the class generated? For example:

class ChattyType(type):
    def __new__(cls, name, bases, dct):
        print "Allocating memory for class", name
        return type.__new__(cls, name, bases, dct)
    def __init__(cls, name, bases, dct):
        print "Init'ing (configuring) class", name
        super(ChattyType, cls).__init__(name, bases, dct)

if I want to create two different class A and B with different behaviours like this :

A = ChattyType(arg='xxx')
B = ChattyType(arg='yyy')

how to modify the ChattyType code ?		

        BruceKL WhoH
        BruceWhoHKL at gawab.com
          2004-08-18


More information about the Python-list mailing list