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"))。

  • 相关阅读:
    django 添加字段, migrate时候生成一个默认值
    django 开发经验
    GeoIP2-python
    一些好用的django模块
    ubuntu linux samba
    动画工作室
    以太坊dApp全栈开发教程(引言)
    社交网络去中心化已成趋势,读懂核心底层技术选择和路线
    CryptoCurrency Security Standard (CCSS)
    HARNESS THE POWER OF DISTRIBUTED STORAGE IPFS AND SWARM IN ETHEREUM BLOCKCHAIN APPLICATIONS
  • 原文地址:https://www.cnblogs.com/gangzi4321/p/10943635.html
Copyright © 2011-2022 走看看