Find directory name of file?

Grant Edwards grante at
Sun Jan 29 17:40:47 EST 2006

On 2006-01-29, jmdeschamps at <jmdeschamps at> wrote:

> also the function os.cwd() 

Neither os.path nor os.cwd are going to tell you the location
of the python program being executed.

Looking at the value of sys.argv[0] is probably the best bet.
If it's a relative path, then you can use os.path to convert it
to an absolute path if you like:

Try something like this at the beginning of your program and
see if it does what you want:

  print os.path.abspath(sys.argv[0])

Grant Edwards                   grante             Yow!  It's the land of
                                  at               DONNY AND MARIE as promised
                                 in TV GUIDE!

More information about the Python-list mailing list