summaryrefslogtreecommitdiffstats
path: root/askbot/utils/loading.py
blob: 5c57c019054a1c4a5ac4420a99b150a48f60ca48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""Utilities for loading modules"""

def load_module(mod_path):
    """an equivalent of:
    from some.where import module
    import module
    """
    assert(mod_path[0] != '.')
    path_bits = mod_path.split('.')
    if len(path_bits) > 1:
        mod_name = path_bits.pop()
        mod_prefix = '.'.join(path_bits)
        _mod = __import__(mod_prefix, globals(), locals(), [mod_name,], -1)
        return getattr(_mod, mod_name)
    else:
        return __import__(mod_path, globals(), locals(), [], -1)