configparser类库使用

简介: configparser类库使用

一、configparser类库使用

# coding=utf-8
"""
    作者:gaojs
    功能:
    新增功能:
    日期:2022/5/15 21:56
"""
import configparser
def create_config():
    """
    创建配置文件
    :return: 
    """
    config = configparser.ConfigParser()
    config['DEFAULT'] = {'serveraliveinterval': '4',
                         'compression': 'yes',
                         'compressionlevel': '9'}
    config['username'] = {}
    config['username']['admin'] = 'gaojianshuai'
    config['username']['array'] = 'gaojs'
    config['topsecrect'] = {}
    topsecrect = config['topsecrect']
    topsecrect['port'] = '22'
    with open('configuration.ini', 'a') as configfile:
        config.write(configfile)
def read_config():
    """
    读取配置文件
    :return:
    """
    config = configparser.ConfigParser()
    config.read('configuration.ini')
    for key in config['DEFAULT']:
        print(key)
    config.get('DEFAULT', 'compression')
相关文章
|
XML JSON 测试技术
Python之configparser模块详解和使用
Python之configparser模块详解和使用
61 0
Python之configparser模块详解和使用
python configParser配置文件模块
python configParser配置文件模块
|
运维 Ubuntu Linux
【iniparser】项目配置工具iniparser的简单使用
【iniparser】项目配置工具iniparser的简单使用
|
XML JSON 算法
python-常用模块xml、shelve、configparser、hashlib
一、shelve模块 shelve模块也是用来序列化的. 使用方法:   1.open   2.读写   3.close import shelve # 序列化 sl = shelve.
1083 0
|
机器学习/深度学习 Python
Python ConfigParser
ConfigParser 在深度学习中,我打算用这个类来处理参数文件,xx.ini或者xx.cfg。 一、基本操作 1、基本的读取配置文件 read(filename) - 直接读取ini,cfg文件内容 se...
1236 0