import inspect


def varsnamed(*names):
    """Creates a dict from variables names passed as arguments.

    The keys of the dict are the variable names.

    If a variable is not found with the name passed, a NameError exception
    is raised.
    """

    caller = inspect.stack()[1][0]
    vars = {}
    for n in names:
        if n in caller.f_locals:
            vars[n] = caller.f_locals[n]
        elif n in caller.f_globals:
            vars[n] = caller.f_globals[n]
        else:
            raise NameError("name '{0}' is not defined".format(n))
    return vars