diff options
author | Sylvain <syt@logilab.fr> | 2007-09-11 12:54:20 +0200 |
---|---|---|
committer | Sylvain <syt@logilab.fr> | 2007-09-11 12:54:20 +0200 |
commit | b0d5f926d9a79286498cb264e9b798efc7525bc0 (patch) | |
tree | 1618ba0582ef77f123f4780755c30e0a63b17475 /modutils.py | |
parent | d66cc9ebb3c96bb6a3022a1f80b1033af09ee8d7 (diff) | |
download | logilab-common-b0d5f926d9a79286498cb264e9b798efc7525bc0.tar.gz |
new load_module_from_file shortcut function
Diffstat (limited to 'modutils.py')
-rw-r--r-- | modutils.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/modutils.py b/modutils.py index 4ab4656..0c026d3 100644 --- a/modutils.py +++ b/modutils.py @@ -130,6 +130,31 @@ def load_module_from_modpath(parts, path=None, use_sys=1): return module +def load_module_from_file(filepath, path=None, use_sys=1): + """load a Python module from it's path + + :type filepath: str + :param dotted_name: path to the python module or package + + :type path: list or None + :param path: + optional list of path where the module or package should be + searched (use sys.path if nothing or None is given) + + :type use_sys: bool + :param use_sys: + boolean indicating whether the sys.modules dictionary should be + used or not + + + :raise ImportError: if the module or package is not found + + :rtype: module + :return: the loaded module + """ + return load_module_from_modpath(modpath_from_file(filepath), path, use_sys) + + def modpath_from_file(filename): """given a file path return the corresponding splitted module's name (i.e name of a module or package splitted on '.') |