Dynamically create the definition classes from module 'mod'.

def make_definition_classes(mod):
    """Dynamically create the definition classes from module 'mod'."""
    rootpath = "oandapyV20"
    PTH = "{}.definitions.{}".format(rootpath, mod)

    M = import_module(PTH)
    __ALL__ = []  # construct the __all__ variable
    for cls, cldef in M.definitions.items():

        orig, fiV = next(six.iteritems(cldef))
        fiK = orig.replace('-', '_')
        # create the docstring dynamically
        clsdoc = dyndoc.format(cls=cls,
                               PTH=PTH,
                               mod=mod,
                               firstItem=fiK, orig=orig,
                               firstItemVal=fiV)

        # Since we can't change the docstring afterwards (it's readonly)
        # figure this out before and not during ...
        for K, V in cldef.items():
            attrName = K
            if "-" in K:
                attrName = K.replace('-', '_')
                adoc = _doc.format(K, attrName, K)
                clsdoc += adoc

        # the class
        dyncls = type(cls, (object,), {'__doc__': clsdoc})

        definitions = dict()
        for K, V in cldef.items():
            attrName = K
            if "-" in K:
                attrName = K.replace('-', '_')
            setattr(dyncls, attrName, K)  # set as class attributes
            definitions.update({K: V})    # for mapping by __getitem__

        def mkgi():
            def __getitem__(self, definitionID):
                """return description for definitionID."""
                return self._definitions[definitionID]
            return __getitem__

        def mkinit(definitions):
            def __init__(self):
                self._definitions = definitions

            return __init__

        def mkPropDefinitions():
            def definitions(self):
                """readonly property holding definition dict."""
                return self._definitions
            return property(definitions)

        setattr(dyncls, "__getitem__", mkgi())
        setattr(dyncls, "__init__", mkinit(definitions))
        setattr(dyncls, "definitions", mkPropDefinitions())
        setattr(sys.modules["{}.definitions.{}".format(rootpath, mod)],
                cls, dyncls)
        __ALL__.append(cls)

    setattr(sys.modules["{}.definitions.{}".format(rootpath, mod)],
            "__all__", tuple(__ALL__))