Get Path of current Script

Jason Swails jason.swails at gmail.com
Mon Mar 14 15:09:54 EDT 2011


On Mon, Mar 14, 2011 at 11:25 AM, 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.
>

For *nix, many utilities publish conf files in the user's home directory in
some sort of .conf file.  That makes it easy to give each user their own
.conf file (if multiple users will use it), and avoids any kind of
permission issues that arise if your script is in a folder whose write
positions are turned off.  It's also where common resource files are loaded
(same kind of idea).

Examples: ~/.bashrc, ~/.vimrc, ~/.bash_profile, ~/.cshrc, etc.

Alternatives are hard-coding the install directory location as part of the
install process, which is done sometimes as well.  This is easily accessible
from python via

os.environ['HOME']

or

os.getenv('HOME')

All the best,
Jason

-- 
Jason M. Swails
Quantum Theory Project,
University of Florida
Ph.D. Candidate
352-392-4032
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110314/bbc450ef/attachment-0001.html>


More information about the Python-list mailing list