(ctype)
Helper function to take a string with the neon module and
    classname then import and return  the class object

    Arguments:
        ctype (str): string with the neon module and class
                     (e.g. 'neon.layers.layer.Linear')
    Returns:
        class
Helper function to take a string with the neon module and
    classname then import and return  the class object
Helper function to take a string with the neon module and classname then import and return the class object
def load_class(ctype):
    """
    Helper function to take a string with the neon module and
    classname then import and return  the class object

    Arguments:
        ctype (str): string with the neon module and class
                     (e.g. 'neon.layers.layer.Linear')
    Returns:
        class
    """
    # extract class name and import neccessary module.
    class_path = ctype
    parts = class_path.split('.')
    module = '.'.join(parts[:-1])
    try:
        clss = __import__(module)
        for comp in parts[1:]:
            clss = getattr(clss, comp)
        return clss
    except (ValueError, ImportError) as err:
        if len(module) == 0:
            # try to find the module inside neon
            pkg = sys.modules['neon']
            prfx = pkg.__name__ + '.'
            for imptr, nm, _ in pkgutil.iter_modules(pkg.__path__, prefix=prfx):
                mod = importlib.import_module(nm)
                if hasattr(mod, ctype):
                    return getattr(mod, ctype)
        raise err
def load_class ( ctype ) : # extract class name and import neccessary module. class_path = ctype parts = class_path . split ( '.' ) module = '.' . join ( parts [ : - 1 ] ) try : clss = __import__ ( module ) for comp in parts [ 1 : ] : clss = getattr ( clss , comp ) return clss except ( ValueError , ImportError ) as err : if len ( module ) == 0 : # try to find the module inside neon pkg = sys . modules [ 'neon' ] prfx = pkg . __name__ + '.' for imptr , nm , _ in pkgutil . iter_modules ( pkg . __path__ , prefix = prfx ) : mod = importlib . import_module ( nm ) if hasattr ( mod , ctype ) : return getattr ( mod , ctype ) raise err