Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'resulting': 0.04; 'subsequent': 0.05; '(especially': 0.07; 'calls.': 0.09; 'cherrypy': 0.09; 'lines.': 0.09; 'occasionally': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; '""")': 0.16; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'name)': 0.16; 'sio': 0.16; 'stringio': 0.16; 'wrote:': 0.18; 'result.': 0.19; 'value.': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'appear': 0.29; 'wondering': 0.29; 'lines': 0.31; 'quotes': 0.31; 'third': 0.33; 'charset:us-ascii': 0.36; 'handle': 0.38; 'does': 0.39; 'quote': 0.39; 'to:addr:gmail.com': 0.65; 'results': 0.69; 'default': 0.69; 'configparser': 0.84; 'received:50.22': 0.84; 'relate': 0.84; 'rita': 0.84 Date: Mon, 25 Nov 2013 18:29:06 -0600 From: Tim Chase To: Rita Subject: Re: general ConfigParser question In-Reply-To: References: X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385425670 news.xs4all.nl 15874 [2001:888:2000:d::a6]:49050 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60475 On 2013-11-25 18:32, Rita wrote: > I was wondering if the default ConfigParser can handle multi line > strings (especially in the relate section) > > [Relate] > data="parent process A child process B > Parent process B child process C Yes, though I seem to recall that subsequent lines have to be indented: >>> from ConfigParser import ConfigParser as cp >>> from StringIO import StringIO >>> sio = StringIO("""[global] ... one ="first ... second ... third" ... """) >>> c = cp() >>> c.readfp(sio) >>> c.get("global", "one") # Note2: quotes '"first\nsecond\nthird"' >>> sio = StringIO("""[global] ... one =first ... second ... third ...""") >>> c = cp() >>> c.readfp(sio) >>> c.get("global", "one") # Note2: no quotes 'first\nsecond\nthird' Note1: this also strips off leading whitespace on the subsequent lines. Note2: if you quote the values, they appear in the resulting value. So based on this, I occasionally do like CherryPy does and require quotes, then wrap my cp.get(section, name) results in a ast.literal_eval() call to get the corresponding Python result. Alternatively, you can use the cp.getint(), cp.getbool() and cp.getfloat() calls. -tkc