import configparser class ReadConfig: rc = configparser.ConfigParser() # rc.read("cctv.config",encoding="utf-8") # ra = rc["AAAAA"]["aa"] #方式一获取,类似于读取excel的表单 # ra2 = rc.get("AAAAA","aa") #方式二 获取 # print(ra2) # print(ra) # print(rc.items("AAAAA")) # print(rc.sections()) rc.write("ccd.config") rc.add_section("WANGWEI") with open("cctv.config","a+",encoding="utf-8") as fi: rc.write(fi)