Path: csiph.com!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'json': 0.05; 'subject:skip:c 10': 0.07; 'cleaned': 0.09; 'conf': 0.09; 'python': 0.10; 'files.': 0.13; '-tkc': 0.16; 'display,': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'key/value': 0.16; 'optionally': 0.16; 'pairs,': 0.16; 'readable': 0.16; 'row': 0.16; 'wrote:': 0.16; 'config': 0.18; 'gui': 0.18; 'xml': 0.24; 'header :In-Reply-To:1': 0.24; 'least': 0.27; 'behaviour': 0.29; 'option': 0.31; 'another': 0.32; 'subject:) ': 0.32; 'displayed': 0.33; 'file': 0.34; 'info': 0.34; 'something': 0.35; 'there': 0.36; 'possible': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'display': 0.37; 'charset:us-ascii': 0.37; 'things': 0.38; 'log': 0.38; 'files': 0.38; 'format': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'easy': 0.60; 'default': 0.61; 'cecil': 0.84; 'received:162.253': 0.84; 'westerhof': 0.84; 'relating': 0.93 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1438780740329:300617334 X-MC-Ingress-Time: 1438780740329 Date: Wed, 5 Aug 2015 08:18:52 -0500 From: Tim Chase To: python-list@python.org Subject: Re: Most Pythonic way to store (small) configuration In-Reply-To: <87k2teq9tb.fsf@Equus.decebal.nl> References: <87k2teq9tb.fsf@Equus.decebal.nl> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1438781266 news.xs4all.nl 2956 [2001:888:2000:d::a6]:58611 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95015 On 2015-08-02 12:11, Cecil Westerhof wrote: > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways > > I want to write a Python program to display cleaned log files. I do > not think I need a lot of configuration to be stored: > - some things relating to the GUI > - default behaviour > - default directory > - log files to display, including some info > - At least until where it was displayed > > Because of this I think a human readable file would be best. Yet another mostly-built-in option is to just have a simple file of key/value pairs, optionally with comments. This can be read with something like config = {} with open('config.ini') as f: for row in f: row = row.strip() if not row or row.startswith(('#', ';')): continue k, _, v = row.partition('=') config[k.strip().upper()] = v.lstrip() which is pretty straight-forward and easy format to edit. -tkc