天天看點

自動化架構——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())      
自動化架構——PO設計模式自學——參數化配置——ini配置檔案——類讀取(參數化)01
[email_qq]
qq=123456
mm=1sstt
;
[mima]
#r=123
r=12345
t=www.baidu.com      

執行結果:

自動化架構——PO設計模式自學——參數化配置——ini配置檔案——類讀取(參數化)01
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
"""      

繼續閱讀