How can I get the path of my python script?
python
Solution
Prefer to use `__file__`, like this:
os.path.dirname(os.path.realpath(__file__))
Note: using `sys.argv[0]` may not work if you call the script via another script from another directory.
Problem
I am trying to get the path of my python script. I know 'sys.argv[0] gives me the path and the name of my python script. how can I just get the path? I tried: ``` print sys.argv[0] path = sys.argv[0].split("/") scriptpath = "".join(path[0:-1]) ``` But it does not add back the path separator.