Platform-independent way to refer to execute path

Peter Hansen peter at engcorp.com
Wed Jun 25 13:43:51 EDT 2003


MK wrote:
> 
> What would be the best platform-independent way to refer
> to the current (execute) path for a Python script?
> 
>         self.dirname = ???
> 
> This variable should contain directory name for the current path.

The question seems ambiguous to me.  What is the "current path"?
There is a PATH environment variable, but you probably don't mean
that.  There is also a current directory, or "current working directory",
which is accessible through os.getcwd().  Will that do?  If so, make
sure you read the rest of the docs on the "os" module so you'll 
know what is there for later.

-Peter




More information about the Python-list mailing list