def _lookup(self, name=None, create=False):
        """looks up symbol in search path
        returns symbol given symbol name,
        creating symbol if needed (and create=True)"""
        debug = False # not ('force'in name)
        if debug:  print( '====\nLOOKUP ', name)
        searchGroups = self._fix_searchGroups()
        self.__parents = []
        if self not in searchGroups:
            searchGroups.append(self)

        def public_attr(grp, name):
            return (hasattr(grp, name)  and
                    not (grp is self and name in self._private))

        parts = name.split('.')
        if len(parts) == 1:
            for grp in searchGroups:
                if public_attr(grp, name):
                    self.__parents.append(grp)
                    return getattr(grp, name)

        # more complex case: not immediately found in Local or Module Group
        parts.reverse()
        top   = parts.pop()
        out   = self.__invalid_name
        if top == self.top_group:
            out = self
        else:
            for grp in searchGroups:
                if public_attr(grp, top):
                    self.__parents.append(grp)
                    out = getattr(grp, top)
        if out is self.__invalid_name:
            raise NameError("'%s' is not defined" % name)

        if len(parts) == 0:
            return out

        while parts:
            prt = parts.pop()
            if hasattr(out, prt):
                out = getattr(out, prt)
            elif create:
                val = None
                if len(parts) > 0:
                    val = Group(name=prt)
                setattr(out, prt, val)
                out = getattr(out, prt)
            else:
                raise LookupError(
                    "cannot locate member '%s' of '%s'" % (prt,out))
        return out
dataset/ETHPy150Open xraypy/xraylarch/lib/symboltable.py/SymbolTable._lookup/original