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


Groups > comp.lang.python > #75948

Re: The "right" way to use config files

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; 'parser': 0.07; 'arguments': 0.09; 'imported': 0.09; 'parsing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:files': 0.09; 'that).': 0.09; 'def': 0.12; '>on': 0.16; 'argument.': 0.16; 'assignments': 0.16; 'ben,': 0.16; 'effect,': 0.16; 'finney': 0.16; 'globals': 0.16; 'i.e': 0.16; 'message- id:@4ax.com': 0.16; 'namespace?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'suggestion.': 0.16; 'followed': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'replacing': 0.19; 'seems': 0.21; 'command': 0.22; 'import': 0.22; 'aug': 0.22; 'config': 0.24; 'parse': 0.24; 'url:home': 0.24; '(or': 0.24; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'idea': 0.28; 'function': 0.29; 'file': 0.32; 'this.': 0.32; 'skip:m 30': 0.32; 'stuff': 0.32; "i'd": 0.34; 'could': 0.34; 'but': 0.35; '+0200,': 0.36; 'view,': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; 'responsible': 0.36; 'application': 0.37; 'level': 0.37; 'ben': 0.38; 'to:addr:python-list': 0.38; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'how': 0.40; 'new': 0.61; 'making': 0.63; 'name': 0.63; 'subject:The': 0.64; 'bottom': 0.67; 'default': 0.69; 'configparser': 0.84; 'everything,': 0.84; 'received:108': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: The "right" way to use config files
Date Sat, 09 Aug 2014 12:16:56 -0400
Organization IISS Elusive Unicorn
References <ls51q0$4ea$1@speranza.aioe.org> <mailman.12792.1407586666.18130.python-list@python.org> <ls54fh$aoe$1@speranza.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host adsl-108-79-217-116.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 6.00/32.1186
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12794.1407601013.18130.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407601013 news.xs4all.nl 2975 [2001:888:2000:d::a6]:49523
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75948

Show key headers only | View raw


On Sat, 09 Aug 2014 14:33:54 +0200, Fabien <fabien.maussion@gmail.com>
declaimed the following:

>Hi Ben,
>
>On 09.08.2014 14:17, Ben Finney wrote:
>> Have one module of your application be responsible for the configuration
>> of the application::
>>
>>      # app/config.py
>>
>>      import configparser
>>
>>      parser = configparser.ConfigParser()
>>      parser.read("app.conf")
>
>Thanks for the suggestion. This way to do is new to me, and I didn't 
>come to the idea myself. It seems like a good way to do this. But how to 
>give an argument to this config namespace? i.e I want "app.conf" to be 
>given as argument.
>
	Well, you could let the module access the command line arguments
directly (though I'd recommend against that). In effect, the bottom of the
imported module would have all the 

	sys.argv...

stuff followed by parsing the file provided file name (or a default set of
settings).

	Better, in my view, is to have the import module set up default values
for everything, AND have a function at the bottom of the form

def initialize(fid=None):
	if fid:
		# parse file "fid" replacing the module level items
		# this may require making a them all globals since
		# assignments inside this function would be locals

And then your main program

import myconfig
...
myconfig.initialize(sys.argv[1])

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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