[Tutor] finding directory of self

Alan Gauld alan.gauld at btinternet.com
Tue Mar 29 10:16:32 CEST 2011

"Rance Hall" <ranceh at gmail.com> wrote

> osname = os.name
> pathtocfg = os.path.dirname(sys.argv[0])
> configfileloc = os.path.abspath(pathtocfg)
> os.chdir(configfileloc)
> to set the directory of all subsequent file lookups in a script.

This is not the most user friendly thing to do. Some sys admins
require config files (and indeed all data) to be located separately
from programs. It would be more friendly to provide the option
of defining the config file location, perhaps via an environment

Of course if the env variable is not defined you probably still need
this code for the default location, in which case Wayne's suggestion
should work. (Alternatively throw an error insisting the EV be set up)

And if you are not deploying this to more than one operating
envioronment where you know the policy then its a moot
point anyway.

Alan G.
Back from his vacation :-)

More information about the Tutor mailing list