Christopher Arndt wrote:
Scott Oertel schrieb:
I'm looking for an easy way to find the current directory location of my
program so I can include the config.ini file correctly without having to
pass command line args.
So, do you want to find out, where your script is living, or the directory from
which it was called (the "working directory")?
The former can be found out like this:
Assuming cron calls your script with the full path name (which should be the
case because it uses the shell to execute your script):
import os, sys
mydir = os.path.dirname(sys.argv[0])
When you want the current working directory:
import os
mydir = os.getcwd()
Then to get the path to your config file, either:
config_path = os.path.join(mydir, 'config.ini')
HTH, Chris
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
It was this one:
mydir = os.path.dirname(sys.argv[0])
thanks man, it was starting to drive me nuts :)
-Scott Oertel
-Gawr.com!
|
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor