import importlib


def cfg_instantiate(cfg, *args, **kwargs):
    """Create a instance of a class specified in cfg."""
    package_name, classname = cfg.classname.rsplit(".", 1)
    package = importlib.import_module(package_name)
    constructor = getattr(package, classname)
    obj = constructor(*args, **(cfg.kwargs or {}), **kwargs)
    return obj