Sunday, March 15, 2009

python append application working directories subdirectory to sys.path

This is a little script to show how to append the application working directories subdirectories when os.environ['PWD'] _not_ in application directory


#!/usr/bin/env python
import os,sys
print __file__
print os.environ["PWD"]
s=os.environ["PWD"]+"/"+os.path.dirname(__file__)
sys.path.append(s+"/python_stdout_colors")
print sys.path



doing only os.environ['PWD'], os.get_cwd() or os.path.dirname is _not_ enough and will cause errors in your application if a user opens it in different directory than where the script is

No comments: