Return a String of the Path the Running Python Program Resides In

Anyone know if there is a rs method that returns the path name of the currently executing python script?

I have data in subfolders of my python code folder that I’d like to access. But I don’t want to code an absolute path to that folder.

Thoughts anyone?


Hi Mark,

not shure if this runs on mac but it worked here to get the path with file name under win7:

import os
p = os.path.realpath(__file__) 

and this one to strip only the path without filename:

import os
print os.path.dirname(os.path.realpath(__file__))


Thanks. Doing os.path.realpath("./") worked nicely.