Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98705
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: can ConfigParser deal with repeating section header? |
| Date | Thu, 12 Nov 2015 09:59:54 -0600 |
| Lines | 47 |
| Message-ID | <mailman.276.1447346408.16136.python-list@python.org> (permalink) |
| References | <95dc81c4-31eb-4f45-8b9c-20a03b2f0caa@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de Isx2a1HRB76erhUuRNEoKgSoHQ6ie3yTyeZ7YnwSjetA== |
| Return-Path | <python.list@tim.thechases.com> |
| 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; 'cc:addr:python-list': 0.09; '""")': 0.09; 'stringio': 0.09; "'b'": 0.16; '-tkc': 0.16; 'arrays.': 0.16; 'cstringio': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'key:': 0.16; 'possible?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'settings': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'cc:no real name:2**0': 0.22; 'import': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'values': 0.28; 'file': 0.34; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'charset:us-ascii': 0.37; 'subject:with': 0.40; 'john': 0.61; 'hope': 0.61; 'received:50': 0.66; 'note:': 0.66; 'configparser': 0.84; 'ini': 0.84 |
| 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 | 1447344082132:599569410 |
| X-MC-Ingress-Time | 1447344082132 |
| In-Reply-To | <95dc81c4-31eb-4f45-8b9c-20a03b2f0caa@googlegroups.com> |
| X-Mailer | Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) |
| 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 <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> |
| Xref | csiph.com comp.lang.python:98705 |
Show key headers only | View raw
On 2015-11-12 07:47, John Zhao wrote:
> I have a configuration file with repeating sections, for example,
>
> [INSTANCE]
> Name=a
>
> [INSTANCE]
> Name=b
>
> I hope I can use ConfigParser to read the file and store the
> configuration settings in arrays.
>
> Is that possible?
Not with the standard library's ConfigParser:
>>> from cStringIO import StringIO
>>> from ConfigParser import ConfigParser
>>> ini = StringIO("""[INSTANCE]
... Name=a
...
... [INSTANCE]
... Name=b
... """)
>>> cp = ConfigParser()
>>> cp.readfp(ini)
>>> cp.sections() # note: only one section
['INSTANCE']
>>> cp.get("INSTANCE", "Name") # note: only the last value
'b'
It also fails to catch multiple values with the same key:
[INSTANCE]
Name=a
Name=b
doesn't give you
cp.get("INSTANCE", "Name") == ["a", "b"]
-tkc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
can ConfigParser deal with repeating section header? John Zhao <johnzzhao@gmail.com> - 2015-11-12 07:47 -0800 Re: can ConfigParser deal with repeating section header? Tim Chase <python.list@tim.thechases.com> - 2015-11-12 09:59 -0600 Re: can ConfigParser deal with repeating section header? amorawski@magna-power.com - 2015-11-12 11:38 -0800
csiph-web