'Lookup name in a namespace spanning sys.modules and __main.dict__'

def get_entity(self, name):

    if name:
        namespace = sys.modules.copy()
        namespace.update(__main__.__dict__)
        try:
            return eval(name, namespace)
        except (NameError, AttributeError):
            return None
