zoukankan      html  css  js  c++  java
  • 配置文件

    1、配置文件

     2、配置文件常见的格式

    .ini       .conf      .cfg

    3、配置文件对象

    section     option

    4、读写配置文件的内容

    from configparser import ConfigParser

    # 创建一个操作配置文件的对象(文件解析对象)
    conf = ConfigParser()

    # 读取配置文件中的内容
    conf.read("conf.ini", encoding="utf8")

    # get方法:读取出来的内容,都是字符串
    # res1 = conf.get("logging", "level")
    # print(res1, type(res1))

    # getint:读取整数类型的数据,读取出来是int类型
    # res3 = conf.getint("musen","age")
    # print(res3,type(res3))

    # getfloat:读取浮点数
    # res4 = conf.getfloat("musen", "money")
    # print(res4)

    # getboolean:读取布尔值
    # res5 = conf.getboolean("musen", "switch")
    # print(res5, type(res5))

    # 配置数据的写入
    conf.set("544e35", "bbb", "python")
    conf.write(open("conf.ini", "w",encoding="utf-8"))
  • 相关阅读:
    2020-12
    知识的深度跟知识的广度
    限额类费用报销单N+1原则
    用友实习总结
    NC57,NC63-NC二开经验总结
    union和union all的区别
    2020
    mark_rabbitMQ
    营销之路
    怎么对ORACLE里的CLOB字段进行模糊查询
  • 原文地址:https://www.cnblogs.com/python-squirrel/p/12145737.html
Copyright © 2011-2022 走看看