configparser类库使用
【摘要】
一、configparser类库使用
# coding=utf-8""" 作者:gaojs 功能: 新增功能: 日期:2022/5/15 21:56"""import configparser def create_config(): """ 创建配置文件 :return: ...
一、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')
文章来源: blog.csdn.net,作者:懿曲折扇情,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_41332844/article/details/126837356
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者

评论(0)