runtime location discovery
Geoff Gerrietts
geoff at gerrietts.net
Fri Mar 29 20:48:32 EST 2002
I'm writing a program designed for maximal flexibility, with minimal
dependencies.
The other night, I tried to put in a chunk of code that allowed the
program to be executed from an arbitrary location (like a user's home
directory) without previously knowing where we were installed
(allowing the app to be installed wherever it seems most natural to
the system administrator).
The code I wrote did this:
root_location = os.path.dirname(sys.argv[0])
Later, I could use root_location as a prefix in statemnts like:
Image.open(os.path.join(root_location, "image/naked_chicks.png"))
or whatever ;)
That worked famously, but infamy was a mere logical step away.
When I created a symlink to the script, it went shopping for the
resource files at all in ~geoff/bin/ instead of ~geoff/src/sp/.
Obviously, it didn't find them.
Now I can go look for symlinks and resolve them, that's not a problem.
But a hard link would create the same problem all over again. So I'm
curious -- this can't be an uncommon hurdle to hop. How have other
people solved the problem?
Thanks,
--G.
--
Geoff Gerrietts <geoff at gerrietts dot net> http://www.gerrietts.net/
"If I were two-faced, would I be wearing this one?" --Abraham Lincoln
More information about the Python-list
mailing list