python自动化之封装获取配置文件

python自动化之封装获取配置文件,第1张

python自动化封装获取配置文件 封装获取配置文件:
# config.ini
[logging]
name = zangai
level = DEBUG
filename = testlog.log
sh_level = DEBUG
fh_level = INFO

[env]
base_url = http://api.dsad.site:8000

[test_data]
username = 
password = 
[invest_user]
mobile= 
pwd= 
[test_admin]
mobile= 
pwd=
[mysql]
host = api.lemonban.com
port = 3306
username = 
password = 
from configparser import ConfigParser
import os
from commons.handle_path import CONF_DIR

# handle_config
class Config(ConfigParser):
    def __init__(self,conf_file):
        super().__init__()
        self.read(conf_file,encoding='utf-8')

conf=Config(os.path.join(CONF_DIR,'config.ini'))
print(conf.get("mysql", "host"))
print(conf.getint("mysql", "port"))

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5680442.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存