I uploaded a module named symboldict to the python package index (pypi). This snippet shows how to use it to create a dictionary of symbols from various modules. This dictionary can be used as a common language shared by several modules. It can be used to load python libraries in a lazy way. It also brings the power of python dictionaries to manipulate collections of functions.

"""This script demonstrates how to use module symboldict"""
# python 2 and 3

from symboldict import symbol, SymbolDict

# This symboldict instance refers symbolically to functions
# living in various modules. It defines a glossary of functions
# used in this script an potentially shared by other modules.

sy = SymbolDict(
    print_exc = symbol.traceback.print_exc,
    isdir = symbol.os.path.isdir,
    mkdtemp = symbol.tempfile.mkdtemp,
    pjoin = symbol.os.path.join,
    rmtree = symbol.shutil.rmtree,
    sleep = symbol.time.sleep,
    Tempdir = symbol.tempfile.TemporaryDirectory,

# The following code uses the symboldict to access external functions.
# The corresponding modules are imported lazily when they are needed

def function():
    root = sy.mkdtemp()
        spamfn = sy.pjoin(root, "spam.txt")
            x = 1/0
        except Exception as exc:
            with open(spamfn, 'w') as spam:  
            with open(spamfn) as spam:
    return root

if __name__ == '__main__':
    root = function()
    print('please wait ...')
    if sy.isdir(root):
        print('Directory {} still exists'.format(root))
        print('Directory {} has been removed'.format(root))
About the Author
Member Avatar Gribouillis Programming Explorer

Mind explorer.

Upgrade today to version 0.3.0! It is an optimized version with respect to the efficiency of attribute access. To upgrade, use

pip install --upgrade symboldict

2015 jan 18

Edit: I hope some members of this forum will use symboldict in their programs and give some feedback in this thread!