class Base type def __new__ cls name bases dic cls initialize dic retu

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Base(type):
def __new__(cls, name, bases, dic):
cls.initialize(dic)
return super(Base, cls).__new__(cls, name, bases, dic)
@classmethod
def initialize(cls, dic):
for field in dic['fields']:
dic[field] = 666
class Acc(object):
__metaclass__ = Base
fields = ('a', 'b', 'c')
print Acc.a
print Acc.b
print Acc.c