Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'skip:[ 20': 0.03; 'json': 0.05; 'default.': 0.07; 'linear': 0.07; 'subject:skip:c 10': 0.07; 'snippet': 0.09; 'python': 0.10; 'weird': 0.15; '(small)': 0.16; '>on': 0.16; 'advocating': 0.16; 'files...': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'quoted': 0.16; 'readable': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'shallow': 0.16; 'simpson': 0.16; 'structure.': 0.16; 'wrote:': 0.16; 'nested': 0.18; 'skip': 0.18; '>>>': 0.20; '2015': 0.20; 'aug': 0.20; 'otherwise,': 0.20; 'cheers,': 0.22; 'file.': 0.22; 'bruce': 0.23; 'header:In-Reply- To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'parameters': 0.27; 'scale': 0.27; 'embed': 0.29; 'handled': 0.29; 'skip:[ 10': 0.31; 'probably': 0.31; 'subject:) ': 0.32; 'received:com.au': 0.33; 'rule': 0.33; 'skip:/ 20': 0.33; 'structure': 0.34; 'file': 0.34; 'could': 0.35; 'text': 0.35; 'besides': 0.35; 'i.e.': 0.35; 'quite': 0.35; 'something': 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; '(and': 0.36; 'basic': 0.36; 'data.': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'agree': 0.37; 'green': 0.38; 'names': 0.38; 'stuff': 0.38; 'log': 0.38; 'several': 0.38; 'mean': 0.38; 'why': 0.39; 'data': 0.39; 'format': 0.39; 'does': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'some': 0.40; 'easy': 0.60; 'reach': 0.61; 'school': 0.62; 'course': 0.62; 'flat': 0.63; 'more': 0.63; 'within': 0.64; 'cameron': 0.66; 'incorporate': 0.66; 'skip:\xe2 10': 0.70; 'sunday': 0.72; 'barber': 0.84; 'cecil': 0.84; 'commenting': 0.84; 'compelling': 0.84; 'complexity': 0.84; 'eg:': 0.84; 'fields,': 0.84; 'hole,': 0.84; 'ini': 0.84; 'roman': 0.84; 'westerhof': 0.84; '8bit%:33': 0.91; 'tricky': 0.93 Date: Mon, 3 Aug 2015 08:49:30 +1000 From: Cameron Simpson To: python-list@python.org Subject: Re: Most Pythonic way to store (small) configuration MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87fv41r5vv.fsf@Equus.decebal.nl> User-Agent: Mutt/1.5.23 (2014-03-12) References: <87fv41r5vv.fsf@Equus.decebal.nl> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=XMDNMlVE c=1 sm=1 tr=0 a=7VRakydLWw4CnqwyGz1TSg==:117 a=7VRakydLWw4CnqwyGz1TSg==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=vrnE16BAAAAA:8 a=yEdEr6MRgwAA:10 a=IkcTkHD0fZMA:10 a=uRRa74qj2VoA:10 a=zLr-PlEfOKFXcPmdpvUA:9 a=QEXdDO2ut3YA:10 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: 77 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1438555783 news.xs4all.nl 2844 [2001:888:2000:d::a6]:49510 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:94904 On 02Aug2015 18:51, Cecil Westerhof wrote: >On Sunday 2 Aug 2015 13:54 CEST, Ben Finney wrote: >> Cecil Westerhof writes: >>> Because of this I think a human readable file would be best. >> >> I agree with that criterion; in the absence of compelling reasons >> otherwise, human-readable and -editable text is a good default. [...] >> The “INI” format as handled by the Python ‘configparser’ module is >> what I would recommend for a simple flat configuration file. It is >> more intuitive to edit, and has a conventional commenting format. > >Well, I would use nested data. (A file will have extra fields besides >the name.) That is why I was thinking about json. But I will look into >it. Like others, I also recommend an INI file. You can always move to something more complex (and harder to edit) if it doesn't work out. Note that "nested data" does not rule out an INI file unless you mean "recursive" data or quite a deep nesting of structure. Shallow structure (one or two levels) is very easy to embed in the INI format. Eg: [main] this = that size = 10 directory = /path/to/default/dir [gui] foreground = green style = baroque [*.log] stuff about log files... [/path/to/file1] title = something param1 = 5 param2 = 6 fields = column2, column7 [column2:/path/to/file1] format = numeric scale = logarithmic [column7:/path/to/file1] format = roman scale = linear See that by being a little tricky about the section names you can incorporate a fair degree of structure? I would not advocating going too fair down that rabbit hole, but for basic stuff it works well. And of course you can put structure within a section: [foo] complexity = {'blah': 'blah blah', 'frib': {'frob': 1, 'frab': 2}} format_width = 10 format_style = right-justified format_dialect = quoted i.e. you could put (small) JSON snippet in some fields, or present a few parameters to describe "format". There are several ways to do this kind of thing before reaching for more complex syntaxes. Just don't let it get too weird - that would probably be a sign you do want to reach for JSON or YAML. But start with INI. Simple and easy. Cheers, Cameron Simpson A squealing tire is a happy tire. - Bruce MacInnes, Skip Barber Driving School instructor