is there a way to determine a relative path to the script?
tekion at gmail.com
Fri Jan 2 20:03:44 CET 2009
I have a script in /usr/local/app/mypython.py and a configuration file
relative to /usr/local/app/conf. When I call the script with an
absolute path of /usr/local/app/mypthon.py I recieved an error
similar to the below error:
Traceback (most recent call last):
File "script/art/auditlog.py", line 28, in ?
database = Config.get("DB", "user")
python2.3/ConfigParser.py", line 505, in get
ConfigParser.NoSectionError: No section: 'DB'
I know why, the configuration which I reference in the script is
relative to "/usr/local/app", when I call the script via an absolute
path, then the relative the configuration file is base on where ever I
call the script from. One way to fix this is to add a path manually
into the variable. But I would like to avoid this hard-coding
parameter into my script. Is there a way to determined the relative
location of the script programatically? FYI, in the end this scrip
would run from CRON.
More information about the Python-list