Python is an object-oriented language and the following is my extension to the Configparaser.configparaser object. Added the Get_client method to the decomposition process of the custom parameter.
#coding =utf-8import configparserimport re# objects inherit from Object Configparser.configparserclass Config (configparser.configparser) : " extract from server list data configuration information Instance [hosts] client = Root:[email Protected]^[email protected]:3306,root:[ Email protected]:3306 Multiple servers are separated by the English bean number Example import libs.configure as config conf = config. Config () conf.read ("default.conf") clinets = Conf.get_client ("Hosts", "Client") " def get_ Client (Self, section, option): Item = self.get (section, option) values = Item.split (",") confs< c17/>= {} for conf in values: match = Re.match (r "(\w+?):(. +) @ ([^:]+):(\d+) ", conf) if match: user,password,host,port = match.groups () confs[host] = {" Host ": Host, "User": User, "password":p assword, "port": Int (port)} return Confs
Learn the object inheritance of Python