Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75939

The "right" way to use config files

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!aioe.org!.POSTED!not-for-mail
From Fabien <fabien.maussion@gmail.com>
Newsgroups comp.lang.python
Subject The "right" way to use config files
Date Sat, 09 Aug 2014 13:48:17 +0200
Organization Aioe.org NNTP Server
Lines 75
Message-ID <ls51q0$4ea$1@speranza.aioe.org> (permalink)
NNTP-Posting-Host QiumuN6L65Hlgy/sg8Mang.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.python:75939

Show key headers only | View raw


Folks,

I am not a computer scientist (just a scientist) and I'd like to ask 
your opinion about a design problem I have. It's not that I can't get my 
program to work, but rather that I have trouble to find an "elegant" 
solution to the problem of passing information to my program's elements. 
I have trouble to be clear in my request so my apologies for the long 
text...

The tool I am developing is a classical data-analysis workflow. Ideally, 
all the program's configurations are located in a single .cfg file which 
I parse with ConfigObg. The file contains I/O informations 
(path_to_input, path_to_output) as well as internal options 
(use_this_function, dont_use_this_one, function1_paramx = y), etc...

Currently, my program is a "super-object" which is initialized once and 
work schematically as follows:

main():
	obj = init_superobj(config file)
	obj.preprocess()
         obj.process()
	obj.write()

the superobj init routine parses the config files and reads the input data.

and a processing step can be, for example:

def process():

	if self.configfile.as_bool('do_funcion1'):
		params = config.parse_function1_params()
		call_function1(self.data, params)
	
	if self.configfile.as_bool('do_funcion2'):
		params = config.parse_function2_params()
		call_function2(self.data2, params)

The functions themselves do not know about the superobject or about the 
configfile. They are "standalone" functions which take data and 
parameters as input and produce output with it. I thought that the 
standalone functions will be clearer and easier to maintain, since they 
do not rely on some external data structure such as the configobj or 
anything.

BUT, my "problem" is that several options really are "universal" options 
to the program, such as the output directory for example. This 
information (where to write their results) is given to most of the 
functions as parameter.

So I had the idea to define a super-object which parses the config file 
and input data and is given as a single parameter to the processing 
functions, and the functions take the information they need from it. 
This is tempting because there is no need for refactoring when I decide 
to change something in the config, but I am afraid that the program may 
become unmaintainable by someone else than myself. Another possibility 
would be at least to give all the functions access to the configfile.

To get to the point: is it good practice to give all elements of a 
program access to the configfile and if yes, how is it done "properly"?

I hope at least someone will understand what I mean ;-)

Cheers and thanks,

Fabien








Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

The "right" way to use config files Fabien <fabien.maussion@gmail.com> - 2014-08-09 13:48 +0200
  Re: The "right" way to use config files Ben Finney <ben+python@benfinney.id.au> - 2014-08-09 22:17 +1000
    Re: The "right" way to use config files Fabien <fabien.maussion@gmail.com> - 2014-08-09 14:33 +0200
      Re: The "right" way to use config files Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-08-09 12:16 -0400
        Re: The "right" way to use config files Fabien <fabien.maussion@gmail.com> - 2014-08-09 19:17 +0200
  Re: The "right" way to use config files Tim Chase <python.list@tim.thechases.com> - 2014-08-09 12:08 -0500
  Re: The "right" way to use config files Terry Reedy <tjreedy@udel.edu> - 2014-08-09 13:29 -0400
    Re: The "right" way to use config files Fabien <fabien.maussion@gmail.com> - 2014-08-09 20:14 +0200
      Re: The "right" way to use config files Terry Reedy <tjreedy@udel.edu> - 2014-08-09 18:30 -0400
        Re: The "right" way to use config files Fabien <fabien.maussion@gmail.com> - 2014-08-10 10:33 +0200

csiph-web