configparser
2018-12-17 17:30:04   0  举报             
     
         
 AI智能生成
  configparser模块
    作者其他创作
 大纲/内容
  配置文件模块    
     为什么要有配置文件    
     将随环境和用户需求变化的部分放到一个文件中,方便运维人员音需配置  
     配置文件是干什么的  
     配置文件名称    
     conf  
     config  
     .ini  
     配置文件生成    
     import configparser
config = configparser.ConfigParser()
config['组名'] = {'key值':'value'}
with open('example.ini', 'w') as configfile:
config.write(configfile)
    config = configparser.ConfigParser()
config['组名'] = {'key值':'value'}
with open('example.ini', 'w') as configfile:
config.write(configfile)
 配置文件应用    
     导入模块    
     import configparser
config = configparser.ConfigParser()
    config = configparser.ConfigParser()
 组名查找    
     config.sections()  
     组名 in config 查看属狗有该组  
     取值方法    
     config['DEFAULT']['Compression']  
     for key in config['bitbucket.org']  
     ......  
     配置文件啥时候写?    
     完成功能交接前  
     编写代码边写配置文件:经验丰富老程序员,知道应该把什么放到配置文件中  
    
 
 
 
 
  0 条评论
 下一页