.pth files and figuring out valid paths..
Emile van Sebille
emile at fenx.com
Tue Jun 9 18:28:23 EDT 2009
On 6/9/2009 3:00 PM rh0dium said...
> I have a .pth file which has some logic in it - but it isn't quite
> It started with this..
> import os, site; site.addsitedir(os.path.join(os.environ["TECHROOT"],
> But that eventually evolved into..
> import os, site; site.addsitedir(os.path.join(os.environ.get
> ("TECHROOT", "/home/tech"), "tools/python/modules"))
> But now I want to check to make sure this directory exists or fall
> back to "/home/tech". That was the point of the environ.get but what
> if someone sets TECHROOT to /dev/null. Well that will break
> things... I tried this but no go. Can someone help me out..
You're not really putting all this on one line are you? If so, that's a
> import os, site; smsc = os.environ.get("TECHROOT", "/home/tech"); if
> not os.path.isdir(smsc): smsc = "/home/tech"; site.addsitedir
> (os.path.join(smsc, "tools/python/Linux/%arch/lib/python2.5/site-
Try it this way...
import os, site
smsc = os.environ.get("TECHROOT", "/home/tech")
if not os.path.isdir(smsc):
smsc = "/home/tech"
> Apparently there is a problem with the if statement???
More information about the Python-list