load_from_optional_package(package_name,
object_name,
dependency_name=None,
task=None)
| source code
|
Works in the same way as load_optional_package, but corresponds to
doing a from X import Y. Note that X and Y do not correspond
directly to package_name and object_name, though. Part of X may be found
in object_name: this is so that the import of the optional package can be
tested before we try loading anything from it, which may generate
unrelated import errors, even if the optional package is installed
correctly.
E.g. instead of doing:
from nltk.model.ngram import NgramModel
we would do:
load_from_optional_package('nltk', 'model.ngram.NgramModel')
so that we can distinguish between errors loading 'nltk' due to its
not being installed and errors importing 'nltk.model.ngram.NgramModel'
due to bugs in the module, incorrect class name, etc.
- Parameters:
package_name - Python path to the optional package root
object_name - remainder of the Python path to the object to be returned.
|