Fetch the repository succeeded.
import configparser
# 创建一个ConfigParser对象
config = configparser.ConfigParser()
# 添加一个section(类似分组的概念)
config['DEFAULT'] = {'debug': 'False', 'log_level': 'INFO'}
config['Database'] = {'host': 'localhost', 'port': '5432', 'user': 'admin', 'password': '123456'}
# 将配置写入到文件中,这里假设保存为config.ini
with open('./config/config.ini', 'w') as configfile:
config.write(configfile)
# 从文件中读取配置
config.read('config.ini')
# 获取特定section下的参数
print(config['Database']['host'])
print(config['DEFAULT']['log_level'])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。