Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30606 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2012-10-02 00:21 +1000 |
| Last post | 2012-10-02 00:21 +1000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: parse an environment file Chris Angelico <rosuav@gmail.com> - 2012-10-02 00:21 +1000
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2012-10-02 00:21 +1000 |
| Subject | Re: parse an environment file |
| Message-ID | <mailman.1704.1349101309.27098.python-list@python.org> |
On Tue, Oct 2, 2012 at 12:12 AM, Jason Friedman <jason@powerpull.net> wrote:
> Let me restate my question. I have a file that looks like this:
> export VAR1=foo
> export VAR2=bar
> # Comment
> export VAR3=${VAR1}${VAR2}
>
> I want this:
> my_dict = {'VAR1': 'foo', 'VAR2': 'bar', 'VAR3': 'foobar'}
>
> I can roll my own, but I'm thinking there is a module or existing code
> that does this. I looked at the os and sys and configparse modules
> but did not see it.
Is there a reason to use that format, rather than using Python
notation? I've at times made config files that simply get imported.
Instead of a dictionary, you'd have a module object:
# config.py
VAR1='foo'
VAR2='bar'
VAR3=VAR1+VAR2
# main file
import config as my_dict
ChrisA
Back to top | Article view | comp.lang.python
csiph-web