NetworkX

Previous topic

open_file

Next topic

License

require

require(*packages)[source]

Decorator to check whether specific packages can be imported.

If a package cannot be imported, then NetworkXError is raised. If all packages can be imported, then the original function is called.

Parameters :

packages : container of strings

Container of module names that will be imported.

Returns :

_require : function

The decorated function.

Raises :

NetworkXError :

If any of the packages cannot be imported :

Examples

Decorate functions like this:

@require('scipy')
def sp_function():
    import scipy
    pass

@require('numpy','scipy')
def sp_np_function():
    import numpy
    import scipy
    pass