**Duplicate of: [In Python, how do I get the path and name of the file that is currently executing?](https://stackoverflow.com/questions/50499/in-python-how-do-i-get-the-path-and-name-of-the-file-that-is-currently-executing)**

I would like to find out the path to the currently executing script.
I have tried os.getcwd() but that only returns the directory I ran the script from not the actual directory the script is stored.
['https://Stackoverflow.com/questions/444376', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/32933/']
In Python, `__file__` identifies the current Python file. Thus:

```
print "I'm inside Python file %s" % __file__

```

will print the current Python file. Note that this works in imported Python modules, as well as scripts.
How about using sys.path[0] 

You can do something like  

'print os.path.join(sys.path[0], sys.argv[0])'

<https://docs.python.org/library/sys.html>