0
点赞
收藏
分享

微信扫一扫

Pytest学习-python读取ini配置文件

J简文 2022-08-07 阅读 56

废话不罗嗦,直接上代码

[host]
api_sit_url = https://api.binstd.com

Pytest学习-python读取ini配置文件_pytest

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project :Pytest
@File :read_ini.py
@IDE :PyCharm
@Author :zhou
@Date :2022/8/7 9:47
"""
import configparser
import os
# 获取settings_ini文件里面的URL
path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "config", "settings_ini")


def read_ini():
config = configparser.ConfigParser()
config.read(path, encoding="utf-8")
return config


print(read_ini()['host']['api_sit_url'])

Pytest学习-python读取ini配置文件_pytest_02

代码不是关键,主要是自己的一个逻辑要有

举报

相关推荐

0 条评论