Duplicate:
In Python, how do I get the path and name of the file that is currently executing?
How do I get the path of a the Python script I am running in? I was doing dirname(sys.argv[0]), however on Mac I only get the filename - not the full path as I do on Windows.
No matter where my application is launched from, I want to open files that are relative to my script file(s).
moduleobject can be created for any script file. Just because something never actually getsimported doesn't make it "not a module". The answer is the same, anyway: treat the script as a module (use some kind of bootstrap if really necessary) and then apply the same technique. - Karl Knechtelopen('images/pets/dog.png')and Python will do the other. - Alba Mendez