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
|
---|---|
Returns : | _require : 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