.pth files and figuring out valid paths..

rh0dium steven.klass at gmail.com
Wed Jun 10 00:00:51 CEST 2009

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..

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-

Apparently there is a problem with the if statement???


More information about the Python-list mailing list