A cleaner, though not shorter, rewriting could be:

from itertools import chain

def ancestors(path):
    while True:
        yield path
        parent = os.path.dirname(path)
        if parent == path:
            break
        path = parent

for dir in chain([os.environ['HOME']],
                  ancestors(os.path.realpath('.'))):
    modules_dir = os.path.join(dir, 'modules')
    if os.path.exists(modules_dir):
        sys.path.insert(0,modules_dir)
        from foo import foo
        break


HTH,
George

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to