configparser 操作配置文件模块

 

创建一个配置文件

 

import configparser
config = configparser.ConfigParser()
config["DEFAULT"] = {'ServerAliveInterval': '45',
                      'Compression': 'yes',
                     'CompressionLevel': '9',
                     'ForwardX11':'yes'
                     }
config['bitbucket.org'] = {'User':'hg'}
config['topsecret.server.com'] = {'Host Port':'50022','ForwardX11':'no'}
config['path'] = {
    'Base_Path' : 'E:\s17\day28\周末作业讲解',
    'students_path' :'E:\s17\day28\周末作业讲解\students'
}
with open('example.ini', 'w',encoding='utf-8') as configfile:
   config.write(configfile)

 

执行结果:

[DEFAULT]
serveraliveinterval = 45
compression = yes
compressionlevel = 9
forwardx11 = yes

[bitbucket.org]
user = hg

[topsecret.server.com]
host port = 50022
forwardx11 = no

[path]
base_path = E:\s17\day28\周末作业讲解
students_path = E:\s17\day28\周末作业讲解\students
文件名是example.ini

相关文章:

  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2022-02-08
  • 2021-10-25
  • 2021-09-23
  • 2021-07-14
相关资源
相似解决方案