1、ini文件说明
ini文件由节(section)、键(option)、值(value)组成,如下:
[Mysql]
host=10.11.1.1
port=3306
;我是注释,以分号开头的就是注释
;system就是节section
[System]
;host就是键option,=号后边是value值
host=10.11.1.1
port=443
user=test
passwd=test!@#
proxies=None
2、python封装
# 这个log封装的样例可以参考:这是一个我会补上的链接
# 可以先试用print
from common import log
import configparser
import os
log = log.Logs()
class IniCfg:
def __init__(self):
self.conf = configparser.RawConfigParser()
# 配置文件路径
proDir = os.path.split(os.path.realpath(__file__))[0]
self.cfgpath = os.path.join(proDir, "config.ini")
# 检查section是否存在
def checkSection(self, section):
try:
self.conf.read(self.cfgpath)
self.conf.items(section)
except configparser.NoSectionError: