Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"if': 0.04; 'library,': 0.05; 'desired.': 0.07; 'received:edu.au': 0.07; 'terry': 0.07; 'url:bitbucket': 0.07; 'python': 0.08; '2004': 0.09; 'keys,': 0.09; 'storing': 0.09; 'subclass': 0.09; 'to:addr:python.list': 0.09; 'to:addr:tim.thechases.com': 0.09; 'to:name:tim chase': 0.09; 'essentially': 0.10; 'am,': 0.12; 'sections': 0.13; 'method.': 0.15; 'altered': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'function).': 0.16; 'in-memory': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'parser,': 0.16; 'preserved': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'reedy': 0.16; 'sequence.': 0.16; 'start?': 0.16; 'subject:which': 0.16; 'cc:addr:python-list': 0.16; 'looked': 0.16; 'this:': 0.16; 'wrote:': 0.18; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; 'wrote': 0.21; 'file,': 0.21; 'header:In-Reply-To:1': 0.22; 'documented': 0.23; 'coordinate': 0.24; 'shell': 0.24; "i'm": 0.28; 'script': 0.28; 'assuming': 0.29; 'problem': 0.29; 'cc:addr:python.org': 0.29; 'behaves': 0.30; 'comments.': 0.30; 'config': 0.30; 'logic': 0.30; 'standalone': 0.30; 'url:src': 0.30; 'value)': 0.30; 'changes': 0.30; 'minor': 0.32; 'anyone': 0.32; 'does': 0.32; 'changing': 0.32; "isn't": 0.33; 'header:User- Agent:1': 0.33; 'too': 0.33; 'instead': 0.33; 'file': 0.34; 'setting': 0.34; 'apply': 0.35; 'received:au': 0.36; 'cc:2**1': 0.36; 'fair': 0.37; 'minimal': 0.37; 'but': 0.37; 'charset:us- ascii': 0.37; 'enough': 0.38; 'patch': 0.38; 'could': 0.38; 'should': 0.38; 'url:org': 0.39; 'that.': 0.39; 'point': 0.40; 'might': 0.40; 'easy': 0.60; 'back': 0.60; 'john': 0.61; 'more': 0.61; 'efficient': 0.62; 'received:202': 0.66; 'imagine': 0.66; 'anything,': 0.73; 'low': 0.74; 'subject: ': 0.74; 'cameron': 0.77; 'difference.': 0.84; 'gain.': 0.84; 'semantics,': 0.84; 'setting,': 0.84; 'subject:there': 0.91; 'url:css': 0.95 Date: Fri, 16 Mar 2012 08:42:24 +1100 From: Cameron Simpson To: Tim Chase Subject: Re: Is there a ConfigParser which keeps comments MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <4F60DFB8.8080703@tim.thechases.com> User-Agent: Mutt/1.5.21 (2010-09-15) References: <4F60DFB8.8080703@tim.thechases.com> Cc: python-list@python.org, Terry Reedy X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1331847636 news.xs4all.nl 6922 [2001:888:2000:d::a6]:50218 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21715 On 14Mar2012 13:13, Tim Chase wrote: | On 03/14/12 12:06, Terry Reedy wrote: | > On 3/14/2012 6:07 AM, Gelonida N wrote: | >> Now I'm looking for a library, which behaves like config parser, but | >> with one minor difference. | >> | >> The write() mehtod should keep existing comments. | > | > Assuming that you have not overlooked anything, I would just subclass | > ConfigParser with an altered write method. |=20 | It would require a lot more than that. It would entail changing=20 | the reading as well so that it preserved the comments as well as=20 | the order of sections & keys, and a way of storing those=20 | associated comments in sequence. I looked into it a fair while=20 | back and it was a LOT more work than I cared to do for minimal=20 | gain. I wimped out and just documented it with "If you use the=20 | ability to (re)write a configuration file, it will not keep any=20 | comments or ordering from any original sources." A low cost approach might be to patch the file instead of transcribing the in-memory state. Not the same semantics, but it would not be too hard to add a patch_config(filename, section, setting, value) that read the old file and wrote a new one with an adjusted section, ignoring the in-memory state (indeed, on that basis the siganture isn't a method but a standalone function). The logic is easy enough that I even wrote a shell script in 2004 to do essentially this: https://bitbucket.org/cameron_simpson/css/src/ef42896872b5/bin/winclausea= ppend One could imagine an efficient python implementation and a ConfigParser subclass that patched the file if a setting got changed, or had a .patch method to apply particular setting changes as desired. Cheers, --=20 Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ =46rom sci.physics: tron@mailzone.com: The only problem is, how do you send a message from Earth to Mars instantly? Does anyone have any ideas about where we can start? John Baez