[Baypiggies] Reading k=v format files

Marc Abramowitz msabramo at gmail.com
Sat Oct 3 21:59:11 CEST 2015

You might look at https://pypi.python.org/pypi/jprops

I use it to convert Java properties files from TeamCity into bash scripts. https://pypi.python.org/pypi/jprops2bash


> 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:
> def grok_auth(authfile):
>    result=dict()
>    with open(authfile) as af:
>        for line in af:
>            k, v = line.strip().split('=', 1)
>            result[k] = v
>    return result
> There must be a better, batteries based way.  Right?            
> -- 
> Please *no* private copies of mailing list or newsgroup messages.
> Rule 420: All persons more than eight miles high to leave the court.
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> https://mail.python.org/mailman/listinfo/baypiggies

More information about the Baypiggies mailing list