python3配置文件模块configparser.ConfigParser
来源:互联网 发布:socket 的类型 知乎 编辑:程序博客网 时间:2024/05/22 06:48
这是fens.conf里的初始内容:
下面是python3中configparser的处理原码:
import configparser
cf = configparser.ConfigParser()
cf.read(“/Users/macxunlei/Desktop/python3/配置文件/config1.conf”)
s = cf.sections() ====>[‘ybp’,’cz’]
o1 = cf.options(“ybp”)====>[‘name’, ‘age’, ‘tel’, ‘address’]
o2 = cf.options(“cz”)====>[‘name’, ‘age’, ‘tel’, ‘address’]
i1 = cf.items(“ybp”)===>[(‘name’, ‘Tester杨’), (‘age’, ‘24’), (‘tel’, ‘18520374632’),(‘address’, ‘安徽阜阳’)]
i2 = cf.items(“cz”)===>[(‘name’, ‘Qianduan陈’), (‘age’, ‘25’), (‘tel’, ‘18629072893’), (‘address’, ‘安徽滁州’)]
i1_name_value = cf.get(“ybp”,”name”) ====> ‘Tester杨’
i1_age_int_value = cf.getint(“ybp”,”age”) ===> 24
i1_age_value = cf.get(“ybp”,”age”) ===> ‘24’
i1_tel_int_value = cf.getint(“ybp”,”tel”) ====> 18520374632
i1_tel_value = cf.get(“ybp”,”tel”) =====> ‘18520374632’
i1_address_value = cf.get(“ybp”,”address”) ====> ‘安徽阜阳’
if cf.has_section(“yb”):
print(“有了yb了!”)
else :
print(“没有sale袁!!现在开始写入:”)
cf.add_section(“yb”)
cf.set(“yb”,”name”,”sale袁”)
cf.set(“yb”,”age”,”27”)
cf.set(“yb”,”tel”,”182903865”)
cf.set(“yb”,”address”,”湖北岳阳”)#现在只是在内存中,可以查看到,但是没有写到文件中
cf.write(open(“/Users/macxunlei/Desktop/python3/配置文件/config1.conf”,”w”))
下面是删除、修改的操作:
(1) 删除selection
if cf.has_section(“s1”):
cf.remove_section(“s1”)
cf.write(open(“a.conf”,”w”))
(2) 删除option
if cf.has_option(“s1”,”o”):
cf.remove_option(“s1”,”o”);
cf.write(open(“a.conf”,”w”))
(3) 修改option
使用set()和新增加一样,这里不再写了
cf.set(“s1”,”option1”,”新值”)
cf.write(open(“a.conf”,”w”))
- python3配置文件模块configparser.ConfigParser
- Python3 配置文件(configparser)
- Python3 配置文件(configparser)
- PYTHON 配置文件模块 ConfigParser
- 解析配置文件ConfigParser模块
- Python 配置文件 ConfigParser 模块
- python-ConfigParser模块【读写配置文件】
- 【ConfigParser模块】Python处理配置文件
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- ConfigParser模块 — 配置文件分析器
- 使用ConfigParser模块解析配置文件
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- Python之配置文件模块 ConfigParser
- Python - ConfigParser模块读写配置文件
- Banner
- Android实现滑动布局使TitleBar文本渐变色
- springboot 获取上下文代码 ApplicationContextAware
- 架构师之路-如何构建rest接口的安全性访问(dubbox+oatuh2+rest)
- Internet上的网络层
- python3配置文件模块configparser.ConfigParser
- Valid Number
- Shiro HelloWord
- SQL的四种连接-左外连接、右外连接、内连接、全连接
- 国内大公司的开源项目一览表
- 电子日历
- LeetCode343
- RedHat Linux下以yum方式安装Mysql5.6,修改默认的安装路径,以及完全卸载Mysql
- 机器学习基石-02-2-PLA何时停下来?