Put this in a file and then run it.
import inspect, os.path def codepath(function): path = inspect.getfile(function) if os.path.isabs(path): return path else: return os.path.abspath(os.path.join(os.getcwd(), path)) print codepath(codepath)
My tests show that this prints the absolute path of the Python script, whether it is run with the absolute path or not. I also successfully tested it when importing from another folder. The only requirement is that the function or equivalent call be present in the file.
wberry
source share