How to find script's directory

Jeffrey Froman jeffrey at
Sun Aug 19 18:48:28 CEST 2007

Papalagi Pakeha wrote:

> I guess I could do it with a little help of os.path.realpath() for all
> those cases where absolute or relative path was used. But how should I
> approach it when it's invoked as plain '' because its directory
> name is in $PATH?

Use the value of __file__ rather than sys.argv[0] -- it contains the
directory information. You may still need to normalize the value using
various os.path functions.


More information about the Python-list mailing list