[Tutor] path

Sheila King sheila@thinkspot.net
Thu, 28 Feb 2002 19:24:11 -0800


On Thu, 28 Feb 2002 21:40:26 -0500, kirk Bailey <idiot1@netzero.net>  wrote
about [Tutor] path:

> ok, I want to have a program tell itself where it lives, so it can
> figure out path information.
> I want it to read a config file, but it has to know where it is, and
> use that to read the config file, so it knows where everything else
> is! 'pwd' in unix would work, and mabe a few other things, but I do
> not seem to stumble over what is needed to do this. when I tell it to
> just open the file 'foo.cf' it stumbles, as when it tries to open
> './foo.cf'! Clue eagerly saught, over.

Here's a snippet from a script I'm currently running that works portably on
both Windows and Linux (so I can test on my home win98 machine and then
upload to my Linux web server for use).

fullpathtoscript = os.path.abspath(sys.argv[0])
scriptdirectory, scriptfile = os.path.split(fullpathtoscript)

You will need to import sys and os modules, of course.

HTH,

-- 
Sheila King
http://www.thinkspot.net/sheila/

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_