hey Guys,
Can anyone recommend a way to find out the install location of a script/app and set it as a variable within that script/app?
The app just creates a bunch of folders. I want it to create the folder relative to where the script/app is installed.
Thanks!
Adam
If, by that, you mean: Is there a way to for a Python module to know its own name and directory? The answer is, of course, yes (there are several).
When a script is called (by command-line or (say) double-clicking, etc.), it gets its sys.argv[0] set to the filename of the scirpt:
- import sys
-
print sys.argv[0]
Another way: Ever module has a __file__ attribute:
- print repr(__file__) # I use repr() because the command-line I used to call the module looked exactly like the output