python-ConfigParser库读取文件

import ConfigParser,re
def read_appnames():
    conf = ConfigParser.ConfigParser()
    conf.read("cmdb.info")
    sections = conf.sections()
    #print sections
    return sections

def get_hj_by_appname(appname):
    conf = ConfigParser.ConfigParser()
    conf.read("cmdb.info")
    sections = conf.sections()
    #print sections
    options = conf.options(appname)
    str0 = str(options)
    hj = re.findall(r"[a-z]{1,4}_ip_[a-z]{1,3}", str0)
    HJ = list(set(hj))
    return HJ

def get_ips_by_appname(appname,HJ):
    conf = ConfigParser.ConfigParser()
    conf.read("cmdb.info")
    sections = conf.sections()
    #print sections
    options = conf.options(appname)
    #print options
    items = conf.items(appname)
    global items
    str1 = conf.get(appname,HJ)
    #print str
    app_ip = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", str1)   //正则匹配IP地址
    print app_ip
    return app_ip

你可能感兴趣的:(python)