is there a way to determine a relative path to the script?
GDoermann at gmail.com
Fri Jan 2 21:46:00 CET 2009
base = __file__.split(os.sep)
I hope this helps.
> 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")
> File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/ConfigParser.py", line 505, in get
> raise NoSectionError(section)
> 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