html如何读取config,获取config信息示例

这篇博客介绍了如何在Python中使用ConfigParser模块来读取和操作配置文件。通过GetConfig类,演示了打开配置文件、获取所有section、检查section、获取section中的选项和键值对、以及通过字符串匹配选项等功能。
摘要由CSDN通过智能技术生成

一、实验环境

1.Windows10x64

2.anaconda4.6.9 + python3.7.1(anaconda集成,不需单独安装)

二、代码示例

# -*- coding: utf-8 -*-

import os

from configparser import ConfigParser, NoSectionError

debug = False

def debug_print(str):

if debug:

print(str)

class GetConfig(ConfigParser):

def __init__(self, defaults=None):

"""

初始化函数

:param defaults:

"""

ConfigParser.__init__(self, defaults=None)

def optionxform(self, optionstr):

"""

解决ConfigParser将键值对强制转换为小写问题

:param optionstr:

:return:

"""

return optionstr

def open_file(self, file_name):

"""

打开config文件夹

:param file_name: config文件路径

:return:

"""

if os.path.exists(file_n

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值