Simple way to get the full path of a running script?
Lee Harr
missive at frontiernet.net
Sun Dec 28 14:54:07 EST 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 ../junk.py
> This is how you invoked me: ../junk.py
> This is the absolute path: /var/tmp/junk.py
>
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