python reads and parses configuration files

 python reads and parses configuration files

def get_config(filepath):
	f = open(filepath, "r")
	config = f.readlines()
	f.close()
	cfgobj = {}
	for index in range(len(config)):
		if config[index].find('#', 0, 1) >= 0:
			continue
		data = config[index].rstrip('\n').replace(" ", "").split('=')
		if 2 == len(data):
			cfgobj[data[0]] = data[1]

	return cfgobj

	
file format:
a=xxx
b=xxx

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example