python 配置文件封装类

# -*- coding: utf-8 -*-
# @Time :2021/3/28 21:08
# @Author :wang-kai
# @tel :15313929271
# @File :配置文件.py

from configparser import ConfigParser

'''读取正数 getint(),getboolean(),'''
class ReadConfig:
def __init__(self, filename):
self.cf = ConfigParser() # 创建对象
self.cf.read(filename, encoding='utf-8') # 打开文件

"""读取数据"""
def get_data(self, section, option):
value = self.cf.get(section, option)
return eval(value)


if __name__ == '__main__':
data = ReadConfig('peizhi.conf').get_data('test_01', 'test')
print(data)
posted @ 2021-03-29 22:09  测试人员-凯  阅读(128)  评论(0编辑  收藏  举报