Parse Erlang configuration file using Python

I want to parse the erlang config file in python. Is there a module for this? This configuration file contains:

[{webmachine, [ {bind_address, "12.34.56.78"}, {port, 12345}, {document_root, "foo/bar"} ]}]. 
+4
source share
2 answers

Unconfirmed and a little rude, but "works" on your example

 import re from ast import literal_eval input_string = """ [{webmachine, [ {bind_address, "12.34.56.78"}, {port, 12345}, {document_root, "foo/bar"} ]}] """ # make string somewhat more compatible with Python syntax: compat = re.sub('([a-zA-Z].*?),', r'"\1":', input_string) # evaluate as literal, see what we get res = literal_eval(compat) [{'webmachine': [{'bind_address': '12.34.56.78'}, {'port': 12345}, {'document_root': 'foo/bar'}]}] 

Then you can β€œcollapse” the list of dictionaries into a simple dict , for example:

 dict(d.items()[0] for d in res[0]['webmachine']) {'bind_address': '12.34.56.78', 'port': 12345, 'document_root': 'foo/bar'} 
+4
source

You can use etf library to analyze erlang terms in python https://github.com/machinezone/python_etf

+4
source

Source: https://habr.com/ru/post/1432676/


All Articles