Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21715
| Date | 2012-03-16 08:42 +1100 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: Is there a ConfigParser which keeps comments |
| References | <4F60DFB8.8080703@tim.thechases.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.705.1331847636.3037.python-list@python.org> (permalink) |
On 14Mar2012 13:13, Tim Chase <python.list@tim.thechases.com> 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. | | It would require a lot more than that. It would entail changing | the reading as well so that it preserved the comments as well as | the order of sections & keys, and a way of storing those | associated comments in sequence. I looked into it a fair while | back and it was a LOT more work than I cared to do for minimal | gain. I wimped out and just documented it with "If you use the | ability to (re)write a configuration file, it will not keep any | 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/winclauseappend 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, -- Cameron Simpson <cs@zip.com.au> DoD#743 http://www.cskk.ezoshosting.com/cs/ From 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 <baez@math.mit.edu: Just use a coordinate system in which the point at which the message is received has the same t coordinate as the point at which the message was sent.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Is there a ConfigParser which keeps comments Cameron Simpson <cs@zip.com.au> - 2012-03-16 08:42 +1100
csiph-web