Simple way to get the full path of a running script?

Lee Harr missive at
Sun Dec 28 20:54:07 CET 2003

>   #!/usr/bin/env python
>   import sys
>   import os
>   me = sys.argv[0]
>   print "This is how you invoked me: %s" % (me,)
>   print "This is the absolute path: %s" % (os.path.abspath(me),)
> Usage:
>   mark at dev /var/tmp/buffer
>   $ python ../
>   This is how you invoked me: ../
>   This is the absolute path: /var/tmp/

Is this going to work well cross platform? How about from IDLE?

I was using sys.path[0] which I thought was working well, but
apparently fails when the script is run from IDLE on windows.

More information about the Python-list mailing list