def lookup(name, namespaces=None, modules=None):
    """
    Look up the given name and return its binding.  Return `None` if not
    found.

    namespaces:
        Iterable of namespaces / dictionaries to search.
    modules:
        Iterable of modules / objects to search.
    """
    if namespaces is not None:
        for namespace in namespaces:
            if name in namespace:
                return namespace[name]
    if modules is not None:
        for module in modules:
            if hasattr(module, name):
                return getattr(module, name)
    return None