Get Path of current Script

Santoso Wijaya santoso.wijaya at gmail.com
Mon Mar 14 15:12:20 EDT 2011


You can make it a required input with default values to sys.argv when you
start the program. Parse the content of the file given by sys.argv, then
cache it in some global module or pass it around as arguments...

That said, if you still want to go the route of knowing where the current
directory of a given script is, I would do:

import os

HERE = os.path.dirname(os.path.abspath(__file__))
CFGFILE = os.path.join(HERE, 'config.cfg')

~/santa


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.
>
>
> thanks
>
>
> Alex
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110314/b23642ac/attachment-0001.html>


More information about the Python-list mailing list