python中的configparser模块

转自:https://www.cnblogs.com/ming5218/p/7965973.html

configparser这个模块是python用来读取ini配置文件的模块

注意:在python2中模块名为ConfigParser,在python3中模块名称为configparser

ConfigParser在python2中的用法:

第一步:初始化

>>> import ConfigParser
>>> config=ConfigParser.ConfigParser()
>>> config.read("test.ini")

第二步:获取所用的section节点

>>> config.sections()

第三步:获取指定section下的options的值

>>> config.options("db")

第四步:获取options下的子节点的值

>>> config.get("db","db_host")

第五步:获取指点section的所用配置信息

>>> config.items("db")

猜你喜欢

转载自www.cnblogs.com/gaoyuxia/p/10647394.html
今日推荐