前言
今天给大家介绍一下,用python怎么快速读写ini配置文件
一、python读文件
import configparser
cfp = configparser.ConfigParser()
cfp.read("test.ini")
'''获取所有的selections'''
selections = cfp.sections()
print(selections) # ['Title1', 'Title2']
'''获取指定selections下的所有options'''
options = cfp.options("Title1")
print(options) # ['key1', 'key2']
'''获取指定selection下的指定option的值'''
value= cfp.get("Title1", "key1"