Metaclass' __init__ Does not Initialize

Michele Simionato mis6 at pitt.edu
Wed Nov 12 13:10:38 CET 2003


"achan" <anabell at sh163.net> wrote in message news:<mailman.649.1068611151.702.python-list at python.org>...
> As I was trying to create a metaclass, I found out that __init__ defined in
> it does not initializes at all <snip>

1. Please, test your attempts before posting, it would be helpful for
   you as for the people who try to understand you.

2. Are you sure you want __slots__? 99.9% of times __slot__ are not needed,
   I never use them, and I would rather NOT have this feature available
   from Python (yes if available from C) since it is an endless cause
   of confusion.

3. Here is an example of a working metaclass with an __init__ as you
   want:

 class CMeta(type):
  def __new__(mcl, name, bases, dic):
    def __init__(self):
      for s in self.seq:
        print s
    newDict = {'__init__': __init__, 'seq' : [123]}
    return super(CMeta,mcl).__new__(mcl, name, bases, newDict)

class Test(object):
  __metaclass__= CMeta

a = Test() #=> 123


You may figure out for yourself your mistakes. 

                     Michele Simionato




More information about the Python-list mailing list