class Fruit(object):

    def __init__(self, color, shape):
        self.color = color
self.shape = shape
apple = {'color': 'red', 'shape': 'sphere'}
pear = {'color': 'yellow', 'shape': 'cone'}
melon = {'color': 'green', 'shape': 'prolate'}
g = globals()
for clsname, attrs in [('Apple', apple), ('Pear', pear), ('Melon', melon)]:

    def temp(attrs):
        g[clsname] = type(clsname, (Fruit,), {'__init__': lambda self:
            Fruit.__init__(self, **attrs)})
temp(attrs)
Python: программно создавать подклассы на основе значений __init__