• python


    # -*- coding:utf-8 -*-
    
    '''
    @project: jiaxy
    @author: Jimmy
    @file: read_config.py
    @ide: PyCharm Community Edition
    @time: 2018-12-06 13:53
    @blog: https://www.cnblogs.com/gotesting/
    
    '''
    
    
    '''
    
    配置文件
    
        .ini   .properties  .conf 等常见配置文件
    
    1. section  :片段
    2. option   :选项
    
        存在配置文件中的数据,读取出来后,全都是字符串类型。
    
    
    '''
    
    import configparser
    
    # 创建一个对象,用来读取配置文件
    cf = configparser.ConfigParser()
    # 读取配置文件
    cf.read('case.conf')
    
    print(cf.sections())
    print(cf.options('Student'))
    
    # section和option的组合,可以确定一个想要的值
    # 获取指定值的方法, get 或者 [][]
    print(cf.get('Student','score'))
    print(cf['Student']['score'])
    
    print(type(cf.get('Student','score')))
    
    
    
    class ReadConfig:
    
        def read_config(self,filename,section,option):
            cf = configparser.ConfigParser()
            cf.read(filename)
            value = cf.get(section,option)
            return value
    
    if __name__ == '__main__':
    
        config = ReadConfig().read_config('case.conf','Student','score')
        print(config)

  • 相关阅读:
    JS常见异常
    Spring boot 的 @Value注解读取配置文件中的00开头的字符串
    常用网址
    IntelliJ使用教程
    eclipse
    swagger
    Mybatis
    Linux常用命令
    阿里云短信
    Flink Checkpoint-轻量级分布式快照
  • 原文地址:https://www.cnblogs.com/gotesting/p/10076481.html
Copyright © 2020-2023  润新知