parse an environment file
Chris Angelico
rosuav at gmail.com
Mon Oct 1 10:21:45 EDT 2012
On Tue, Oct 2, 2012 at 12:12 AM, Jason Friedman <jason at 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
More information about the Python-list
mailing list