A simpler more pythonic approach to adding in



Hi all,

I need a cleaner ( and shorter ) way to to look in my home directory or
any directory for a directory called modules. This is what I currently
have - but it is really ugly. Some a few of you experts point me to a
cleaner more pythonic approach?

mod = 0
if os.path.exists( os.environ['HOME'] + "/modules"):
sys.path.insert( 0, os.environ['HOME'] + "/modules")
mod =1
else:
path = os.environ['PWD']
while path != "/":
if os.path.exists( path + "/modules"):
sys.path.insert( 0, path + "/modules")
mod= 1
path = "/"
else:
path = os.path.split(path)[0]

if mod:
from foo import foo

.



Relevant Pages

  • Re: Maximum List size (item number) limit?
    ... The following code is shorter and I hope cleaner, ... Kriston-Vizi Janos can fix his problem. ...
    (comp.lang.python)
  • Re: Assigning a vector from a repeated vector
    ... My naive solution is: ... Is there a better (shorter, cleaner) way of doing this? ... Make use of the 'repmat' function. ...
    (comp.soft-sys.matlab)
  • Re: help with type-punned warning please
    ... See the new version of my sfreemacro that I just posted. ... It's cleaner ... and shorter (afaik). ...
    (comp.lang.c)
  • Checking for Nulls in Fields
    ... Is there a cleaner way to check for nulls in fields? ... Faster, shorter in ... If Not IsDBNull) Then tmpStrAddress = CStr(drPatients ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Complex Number Support
    ... The using satement makes for cleaner examples ... but I wouldn't use it for production code. ... Prev by Date: ...
    (microsoft.public.vc.language)