ceshi_ini.py
import configparser """ 读取配置文件信息 """ class ConfigParser(): config_dic = {} @classmethod def get_config(cls, config, sector, item): value = None try: value = cls.config_dic[sector][item] except KeyError: cf = configparser.ConfigParser(interpolation=None) # interpolation=None 不限制长度 cf.read(config, encoding='utf8') # 注意ceshi.ini配置文件的路径 value = cf.get(sector, item) cls.config_dic = value finally: return value if __name__ == '__main__': con = ConfigParser() res = con.get_config('ceshi.ini', 'ceshi', 'ceshi') print(res)
ceshi.ini
[ceshi] ceshi = ceshi
标签:__,配置文件,Python,ceshi,value,ini,config From: https://www.cnblogs.com/QYGQH/p/16827388.html