[Tutor] Configuaration files and paths?

Alan Gauld alan.gauld at btinternet.com
Thu Aug 6 02:04:05 CEST 2009


"Allen Fowler" <allen.fowler at yahoo.com> wrote

> What is the recommended way to configure my application 
> find the various database and/or configuration files it needs?

Recommemded by whom? A lot depends on the OS. Apple for 
example have one set of recommendations for MacOS, Windows 
has another and Linux has several to choose from!

> For instance my folder layout:
> 
> /path_to_app/app.py
> /path_to_app/lib/
> /path_to_app/database/
> /path_to_app/config/
> /path_to_app/photos
> 
> .... and so on.  
> I would like to make an .ini in the config folder 

Seems fair enough, however on a Unix system you should also 
consider allowing the user to have their own personalised version 
in their home directory. Thus at startup you get the current user 
ID / home directory and look for a suitable config file. If it exists 
read it, if not read the default one in your config directory.

> 1) How does my main app file find the config file in the first place?

Generally use a relative path so normally your app will run from 
its home folder so you can look in ./config. You might also set a 
system environment variable - for example the CLASSPATH 
or PYTHONPATH variables, or the ORACLE_HOME used by 
Oracle for their database. If the environment var is not set then 
look in ./config

> 2) How should I point to those other folders in the ini file?

Once you locate config the others are simply ../xxx relative 
to config.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list