[Baypiggies] Reading k=v format files

Jeff Quast contact at jeffquast.com
Sat Oct 3 21:06:09 CEST 2015

> On Oct 3, 2015, at 11:58 AM, Ian Zimmerman <itz at buug.org> wrote:
> I have a file providing settings for both a shell script and a python
> program.  It looks like this:
> Foo=bar
> Foo2=baz
> and so on.  I'm looking for a short snippet (I hope for a one liner) to
> grok the file and return a dictionary of the settings.  Trivial, you
> say?  Yes, but this is not the first time I feel this need, and each
> time I find myself rewritting basically the same ditty:

Just happened to write this a few weeks ago also,

        # the output format is 'Key=Value\n[...]', parse to dictionary
        result = dict([line.split('=', 1) for line in stdout.decode('utf8').splitlines()])

More information about the Baypiggies mailing list