Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4504
| From | Unknown Moss <unknownmoss@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | (beginner question) ConfigParser nuances |
| Date | 2011-05-02 15:04 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <d53823a8-bc10-42b4-8fc0-91cc10e1234a@i39g2000prd.googlegroups.com> (permalink) |
Hi - Beginner question here. I'm working with ConfigParser. I'd like
to take a multiline variable and convert it directly to an array.
Seems like a common problem, but I don't see how I can do it without
doing a little parsing in my own code. Here's what I'm doing ...
>>> import ConfigParser
>>> import io
>>> sample = """
... [Example]
... fruit = apple
... orange
... pear
... """
>>> config = ConfigParser.RawConfigParser()
>>> config.readfp(io.BytesIO(sample))
>>> config.get("Example", "fruit")
'apple\norange\npear'
>>> temp = config.get("Example", "fruit")
>>> temp.split()
['apple', 'orange', 'pear']
I'm thinking there's a way to avoid this intermediate temp.split()
step. Is there not a way to move a multiline value straight into an
array using ConfigParser?
Thanks for the help.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar
(beginner question) ConfigParser nuances Unknown Moss <unknownmoss@gmail.com> - 2011-05-02 15:04 -0700
Re: (beginner question) ConfigParser nuances Chris Rebert <clp2@rebertia.com> - 2011-05-02 15:25 -0700
Re: (beginner question) ConfigParser nuances Unknown Moss <unknownmoss@gmail.com> - 2011-05-02 19:56 -0700
csiph-web