In perl, the FindBin module is used to locate directory of original script. What's the best way to get this directory in python?
+5
A:
I don't use Python very often so I do not know if there is package like FindBin but
import os
import sys
bindir = os.path.abspath(os.path.dirname(sys.argv[0]))
should work.
Sinan Ünür
2010-03-29 19:04:39
+6
A:
You can try this:
import os
bindir = os.path.abspath(os.path.dirname(__file__))
That will give you the absolute path of the current file's directory.
Chris R
2010-03-29 19:08:41