zoukankan      html  css  js  c++  java
  • Python基础七--configparser模块

    一、configparser 

      a. 读

      1. 实例化:configparser_handle = configparser.ConfigParser();

      2. 读入:configparser_handle.read("config_document.cfg");

      3. 获取标题:configparser_handle.sections();

      4. 获取标题下列表:item_list = configparser_handle.items('term')

      5.  获取字符值方法:configparser_handle.get(‘term’,‘name’);

      6. 获取整数值方法:configparser_handle..getint(‘term’,‘number’);

      7. 获取布尔值方法:configparser_handle..getboolean(‘term’,‘number’);

      8. 获取浮点值方法:configparser_handle..getfloat(‘term’,‘salary’);

      b. 写

      1. 实例化:configparser_handle = configparser.ConfigParser();

      2. 读入:configparser_handle.read("config_document.cfg",encoding = "utf-8);

      3. 删除整块信息:configparser_handle.remove_section("section_test_one");

      4. 删除块信息内的指定信息:configparser_handle.remove_option("section_test_two","key_three");

      5. 判断是否存在"section_test_one":configparser_handle.has_section("section_test_one");

      6. 判断是否存在"section_test_one"下“key_one”:configparser_handle.has_section("section_test_one","key_one");

      7. 添加section:configparser_handle.add_section("section_new");

      8. 在'section_new'中添加"key_one='gangzi':configparser_handle.set("section_new","key_one","gangzi");

      9. 最后将写的内容写入文件,完成最终写:configparser_handle.write(open("config_document.write","w"))。

  • 相关阅读:
    使用正则匹配数字
    钻石和玻璃球游戏(钻石位置不固定)
    简单绘图
    未解决问题02
    Sqlite3 实现学生信息增删改查
    【Python】科赫雪花绘制
    【Python爬虫】抖音去水印
    【MATLAB】数学计算软件 MathWorks MATLAB R2020a 中文破解版
    【C语言】用指针作为形参完成数据的升序排列
    【C语言】数组名作函数参数完成数据的升序排列
  • 原文地址:https://www.cnblogs.com/gangzi4321/p/10943635.html
Copyright © 2011-2022 走看看