学项目,到底学的是什么?
(1)编程思维的能力
(2)debug高度能力
(3)解决问题的能力
(4)熟悉滚固Python基础(尤其是面向对象)
# ==========================
# @time:2019/11/6 17:42
# @Author:coco
# @File:handle_config_01.py
# @software:PyCharm
# ============================
# configparser是系统自带, 不需要安装
from configparser import ConfigParser
# 1. 创建配置解析器对象
config = ConfigParser()
# 2. 指定读取的配置文件
config.read("testcase.conf", encoding="utf-8")
# 3. 读取数据
# 假设: 每一个区域相当于一个嵌套字典的字典
one_result = config["excel"]["cases_path"]
# get方法跟字典中的get有区别
two_result = config.get("excel","result_col")
# 从配置文件中,使用索引(方括号)或者使用get方法,读取出来的所有数据都是字符串
# 可以使用getint(区域名,选项名)只能读取int、float类型的数据,否则会报错
four_result = config.getfloat("msg","value3")
# 可以使用getboolean(区域名,选项名)来读取布尔类型的数据
# 1.yes、on、true、True --->True
# 2.no、off、false、False --->False
five_result = config.getboolean("msg","value6")
pass
# ==========================
# @time:2019/11/6 19:56
# @Author:coco
# @File:handle_config_02.py
# @software:PyCharm
# ============================
from configparser import ConfigParser
# 1. 创建配置解析器对象
config = ConfigParser()
# 2.写入配置
# config还没有读数据时,可以类似于一个字典
# datas是需要写入的数据
datas = {
"excle":{
"cases_path":"cases.xlsx"
},
"user":{
"username":"H.Y",
"password":"123456"
}
}
for key in datas:
config[key] = datas[key]
with open("write_config.ini","w",encoding="utf-8") as file:
config.write(file)
运行结果:
在这里插入图片描述