Simple way to get the full path of a running script?
Mark McEahern
mark at mceahern.com
Sat Dec 27 19:25:36 EST 2003
On Sat, 2003-12-27 at 18:02, Benjamin Han wrote:
> Duh - the way I described seems to be simple enough:
>
> pathToScript=os.join(os.getcwd(),os.path.split(sys.argv[0])[0])
Or:
#!/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
Cheers,
// m
More information about the Python-list
mailing list