zoukankan      html  css  js  c++  java
  • configparser

    • import configparser
      config = configparser .ConfigParser ()
      config["DEFULT"] = {"a":"1",
                            "b":"2",
                            "c":"3"}
      config["dsadsad.org"] = {}
      config ["dsadsad.org"]["user"] = "hg"
      
      
      
      
      
      with open("example.ini","w") as f:
          config .write(f)
    • config.read("example.ini")
      print(config .sections() )  #块名
      print("dsadsad.org" in config ) #判断块是否在config中
      print(config ["DEFULT"]["A"])  #不区分大小写
    • for key in config ["dsadsad.org"]:     #user     default块中会遍历
                                                # a
                                                #b
          print(key)                            #c
      print(config.options("dsadsad.org")
       #遍历后放在列表中
    • print(config .items("dsadsad.org") )       #将键和值放在元组
      print(config.get("dsadsad.org","a")  )     #因为会遍历默认块,所以可以找到
    • config .add_section("yuan")              #增加块
      config .set("yuan","sdsa","asdsa")    #增加值
      config.remove_section("yuan")            #删除块
      config .remove_option("yuan","sdsa")         #删除值
      config .write(open("i.cfg","w") )
  • 相关阅读:
    【leetcode】二叉搜索树的最近公共祖先
    052-12
    052-11
    052-10
    052-9
    052-8
    052-6
    052-5
    052-3
    052-2
  • 原文地址:https://www.cnblogs.com/alex-anan/p/8470760.html
Copyright © 2011-2022 走看看