How to find script's directory
jeffrey at fro.man
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 'blah.py' because its directory
> name is in $PATH?
Use the value of __file__ rather than sys.argv -- it contains the
directory information. You may still need to normalize the value using
various os.path functions.
More information about the Python-list