read_ini.py 1.11 KB
Newer Older
yzhen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test_56
# FileName:      read_ini.py
# Author:       xxxxxxx
# Datetime:     2023/8/7 15:21
# Description:
# 
# ---------------------------------------------------------------------------
import configparser
import os


class ReadIni:
    def __init__(self):
        """读取ini文件"""
        self.data_config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data_config")
        ini_path = os.path.join(self.data_config_path, 'config.ini')

        self.conf = configparser.ConfigParser()
        self.conf.read(ini_path, encoding="utf-8")

    def get_file_path(self, key):
        return os.path.join(self.data_config_path, self.conf.get("file", key))

    def get_table_name(self, key):
        return self.conf.get("table_name", key)

    def get_host(self, key):
        return self.conf.get("host", key)

    def get_sql_connect_message(self, key):
        return self.conf.get("sql", key)


if __name__ == '__main__':
    read_ini = ReadIni()
    print(read_ini.get_file_path("excel"))