mean-teacher icon indicating copy to clipboard operation
mean-teacher copied to clipboard

what is the role of the export function?

Open yichuan9527 opened this issue 6 years ago • 2 comments

def export(fn):
    mod = sys.modules[fn.__module__]   
    if hasattr(mod, '__all__'):    
        mod.__all__.append(fn.__name__)    
    else:   
        mod.__all__ = [fn.__name__]    
    return fn

I don't understand the useful of the export function?

yichuan9527 avatar May 18 '18 01:05 yichuan9527

Hi,

It is just a way to avoid writing __all__ = etc. at the top of the module. The architectures and data modules contain bunch of internal functions that we want to hide from the rest of the program. Within those modules, the functions that have @export before them are visible to other modules, other functions are invisible.

Hope this helps.

Antti

tarvaina avatar May 24 '18 10:05 tarvaina

Thanks !

yichuan9527 avatar Jun 05 '18 11:06 yichuan9527