How to pass parameters to parent class with type() in python? -
class parent(object):      def __init__(self, first):         self.first = first  class child1(parent):      def __init__(self):         parent.__init__(self, 'a')   - i have parent class , want make 12 similar classes inherit parent class, same signature , no parameters. how define child1, using 
type()? far havechild1 = type('child1', (rank,), dict())how can passfirstparentclass? 
you use attributes dictionary. think should trick.
def genericinit(self):     parent.__init__(self, 'a')  type('child1', (rank,), {'__init__': genericinit})   updated per comments: use functools.partial
attrdict = {'init': functools.partial(parent.__init__, first='a')}   but bad code. don't want calling init anywhere other init because it's confusing using class.
Comments
Post a Comment