def init_func_generator(cls, spec):
 if (not spec):
  def __init__(self):
   pass
  return __init__
 (varnames, defaults) = zip(*spec)
 args = ', '.join(map('{0[0]}={0[1]!r}'.format, spec))
 init = 'def __init__(self, {0}):\n'.format(args)
 init += '\n'.join(map('    self.{0} = {0}'.format, varnames))
 name = '<generated {0}.__init__>'.format(cls.__name__)
 code = compile(init, name, 'exec')
 func = next((c for c in code.co_consts if isinstance(c, types.CodeType)))
 linecache.cache[name] = (len(init), None, init.splitlines(True), name)
 return types.FunctionType(func, {}, argdefs=defaults)

def init_func_generator ( cls , spec ) : if ( not spec ) : def __init__ ( self ) : pass return __init__ ( varnames , defaults ) = zip ( * spec ) args = ', ' . join ( map ( '{0[0]}={0[1]!r}' . format , spec ) ) init = 'def __init__(self, {0}):\n' . format ( args ) init += '\n' . join ( map ( '    self.{0} = {0}' . format , varnames ) ) name = '<generated {0}.__init__>' . format ( cls . __name__ ) code = compile ( init , name , 'exec' ) func = next ( ( c for c in code . co_consts if isinstance ( c , types . CodeType ) ) ) linecache . cache [ name ] = ( len ( init ) , None , init . splitlines ( True ) , name ) return types . FunctionType ( func , { } , argdefs = defaults )
generate __init__ function based on tpayload .