Re: A simpler more pythonic approach to adding in
- From: "George Sakkis" <gsakkis@xxxxxxxxxxx>
- Date: 18 Jan 2006 15:34:06 -0800
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
.
- References:
- A simpler more pythonic approach to adding in
- From: rh0dium
- A simpler more pythonic approach to adding in
- Prev by Date: Re: New Python.org website ?
- Next by Date: understanding stat module names
- Previous by thread: A simpler more pythonic approach to adding in
- Next by thread: Duplicate entries in a matrix
- Index(es):
Relevant Pages
|