Get Path of current Script
Grant Edwards
invalid at invalid.invalid
Mon Mar 14 17:17:49 EDT 2011
On 2011-03-14, Alexander Schatten <aschatt at gmail.com> wrote:
> They don't. Hm, ok, I am always for best practices. If there is a
> better way to do it I am open for suggestions ;-) How would the best
> practice be to load configuration data from a file.
>
> I mean, this is something very common: you write a program or a
> script and want to load some configuration data.
Indeed that is very common, and there's been a "standard" way to do
that since before dirt.
The standard on Unix is to look in the following places in (this
order), and use the first one you find:
1) The location specified by a command line option (-f or -c is
common).
2) The location specified by an environment variable like
MYPROGNAME_CONFIG.
3) The current directory (usually a "hidden" file name like
.myprognamerc or .myprog.config)
4) The current user's home directory -- same file name as 3).
5) The "configuration directory". Each distro has a spec for where
that is, but it's usually _not_ a hidden file name, and is
somemthing like /etc/myprogname.conf or /etc/myprognamerc. For
locally-installed stuff, it's usually /usr/local/etc/muyprog.conf
or something like that.
Notice that it has nothing to do with the location of the program's
executable.
Not all Unix apps look in all 5 places (#2, is probably not quite as
universal as the rest).
Some apps have a directory of config files instead of a single file,
but the general plan is the same.
--
Grant Edwards grant.b.edwards Yow! I smell like a wet
at reducing clinic on Columbus
gmail.com Day!
More information about the Python-list
mailing list