En Tue, 09 Jun 2009 20:30:06 -0300, rh0dium <steven.kl...@gmail.com>
escribió:
On Jun 9, 3:28 pm, Emile van Sebille <em...@fenx.com> wrote:
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
> enough...
> It started with this..
> import os, site; site.addsitedir(os.path.join(os.environ["TECHROOT"],
> "tools/python/modules"))
> But that eventually evolved into..
> import os, site; site.addsitedir(os.path.join(os.environ.get
> ("TECHROOT", "/home/tech"), "tools/python/modules"))
Try it this way...
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-packages"))
No for .pth files this needs to be on a single line..
Try this instead:
import os, site; smsc = os.environ.get("TECHROOT", ""); smsc = smsc if
smsc and os.path.isdir(smsc) else "/home/tech"; site.addsitedir(...)
> 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..
I'd add the directory unconditionally - then, when initializing the
application, I'd check that the required modules can be imported, and
inform the user of that specific problem if not.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list