Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33440
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| 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.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'syntax': 0.03; 'subject:file': 0.07; 'python': 0.09; 'separator.': 0.09; 'cc:addr:python-list': 0.10; 'slightly': 0.15; '-tkc': 0.16; '[section]': 0.16; 'comma': 0.16; 'csv': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'literals:': 0.16; 'message- id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'sorts': 0.16; 'wrote:': 0.17; 'config': 0.17; 'shell': 0.18; 'module': 0.19; 'parse': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'separate': 0.27; 'represent': 0.28; '+0100,': 0.29; 'fri,': 0.30; '(and': 0.32; 'file': 0.32; "skip:' 20": 0.32; 'text,': 0.33; 'list': 0.35; 'nov': 0.35; 'options:': 0.35; 'skip:l 30': 0.35; 'something': 0.35; 'one,': 0.37; 'option': 0.37; 'two': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'skip:a 30': 0.60; 'thomas': 0.62; 'more': 0.63; 'fun': 0.64; 'skip:n 30': 0.69; 'heavy': 0.83; 'configparser': 0.84; 'received:50.22': 0.84 |
| Date | Fri, 16 Nov 2012 07:43:11 -0600 |
| From | Tim Chase <python.list@tim.thechases.com> |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 |
| MIME-Version | 1.0 |
| To | Thomas Bach <thbach@students.uni-mainz.de> |
| Subject | Re: editing conf file |
| References | <k85a7i$sjn$1@poprovec.arnes.si> <k85aoe$uot$1@poprovec.arnes.si> <996a6d6c-fdb2-40a0-bd5c-ada2ba35af78@i2g2000pbi.googlegroups.com> <k85cnl$84o$1@poprovec.arnes.si> <20121116130411.GA4246@taris.box> |
| In-Reply-To | <20121116130411.GA4246@taris.box> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-AntiAbuse | This header was added to track abuse, please include it with any abuse report |
| X-AntiAbuse | Primary Hostname - boston.accountservergroup.com |
| X-AntiAbuse | Original Domain - python.org |
| X-AntiAbuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-AntiAbuse | Sender Address Domain - tim.thechases.com |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3751.1353073345.27098.python-list@python.org> (permalink) |
| Lines | 51 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1353073345 news.xs4all.nl 6873 [2001:888:2000:d::a6]:60841 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:33440 |
Show key headers only | View raw
On 11/16/12 07:04, Thomas Bach wrote:
> On Fri, Nov 16, 2012 at 01:48:49PM +0100, chip9munk wrote:
>> configparser has four functions: get, getboolean, getfloat and getint.
>>
>> how do I get list from cfg file?!
>
> AFAIK you have to parse the list yourself. Something like
>
> my_list = [ s.strip() for s in cp.get('section', 'option').split(',') ]
>
> if you use a comma as a separator.
For slightly more complex option text, you can use the CSV module to
do the heavy lifting, so if you have something like
[section]
option="one, one, one",two,3
then you can have Python give you
my_list = next(csv.reader([cp.get("section", "option")]))
or alternatively use the shlex module and separate them like shell
options:
[section]
option="one, one, one" two 3
then do
my_list = list(shlex.shlex(cp.get("section", "option")))
Or yet one more way using Python list syntax for literals:
[section]
option=["one, one, one", "two", 3]
and get them with
my_list = ast.literal_eval(cp.get("section", "option))
Lots of fun (and batteries-included) ways depending on how you want
to represent the list in the config file and what sorts of data it
can contain.
-tkc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
editing conf file chip9munk <"chip9munk[SSSpAm"@gmail.com> - 2012-11-16 13:06 +0100
Re: editing conf file chip9munk <"chip9munk[SSSpAm"@gmail.com> - 2012-11-16 13:15 +0100
Re: editing conf file rusi <rustompmody@gmail.com> - 2012-11-16 04:35 -0800
Re: editing conf file chip9munk <"chip9munk[SSSpAm"@gmail.com> - 2012-11-16 13:48 +0100
Re: editing conf file Thomas Bach <thbach@students.uni-mainz.de> - 2012-11-16 14:04 +0100
Re: editing conf file chip9munk <"chip9munk[SSSpAm"@gmail.com> - 2012-11-16 14:28 +0100
Re: editing conf file Tim Chase <python.list@tim.thechases.com> - 2012-11-16 07:43 -0600
Re: editing conf file Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-11-16 14:02 +0100
Re: editing conf file chip9munk <"chip9munk[SSSpAm"@gmail.com> - 2012-11-16 14:27 +0100
Re: editing conf file Roy Smith <roy@panix.com> - 2012-11-16 09:08 -0500
Re: editing conf file rusi <rustompmody@gmail.com> - 2012-11-16 08:41 -0800
csiph-web