自动化框架——PO设计模式自学——参数化配置——ini配置文件——类读取(参数化)01

import os
import configparser

proDir = os.path.split(os.path.realpath(__file__))[0]
configPath = os.path.join(proDir, "xs.ini")

class ReadConfig():

    def __init__(self):

        self.parse = configparser.ConfigParser()

        proDir = os.path.split(os.path.realpath(__file__))[0]
        configPath = os.path.join(proDir, "xs.ini")

        self.parse.read(configPath)

    def get_email_qq_qq(self):
        value = self.parse['email_qq']['qq']
        return value

    def get_email_qq_mm(self):
        value = self.parse['email_qq']['mm']
        return value

if __name__ == "__main__":

    cs = ReadConfig()
    print(cs.get_email_qq_qq())
    print(cs.get_email_qq_mm())

 

 

[email_qq]
qq=123456
mm=1sstt
;
[mima]
#r=123
r=12345
t=www.baidu.com

 

 

 

执行结果:

 

 

 

注意:

 

import os

proDir = os.path.split(os.path.realpath(__file__))[0]
print(proDir)
#执行结果: C:\Users\del\PycharmProjects\untitled1\cs



configPath = os.path.join(proDir, "xs.ini")
print(configPath)
#执行结果:C:\Users\del\PycharmProjects\untitled1\cs\xs.ini



"""
proDir = os.path.split(os.path.realpath(__file__))[0]
print(proDir)
#执行结果: C:\Users\del\PycharmProjects\untitled1\cs
------------
configPath = os.path.join(proDir, "xs.ini")
print(configPath)
#执行结果:C:\Users\del\PycharmProjects\untitled1\cs\xs.ini
"""

 

posted @ 2020-04-06 19:10  小白龙白龙马  阅读(234)  评论(0编辑  收藏  举报