readConfig.py 861 Bytes
Newer Older
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 -*-
# @Author: Gree
# @Date:   2021-05-29 14:49:12
# @Last Modified by:   Gree
# @Last Modified time: 2021-05-29 15:02:21


import configparser
import os



class ReadConfig:
    def __init__(self):
        """
        1. 初始化变量
        """
        # 获取 self.dirPath
        self.dirPath = os.path.split(os.path.realpath(__file__))[0]
        # 获取 self.filePath
        self.filePath = os.path.join(self.dirPath, "stopWord.conf")
        # 生成 cf 对象
        self.cf = configparser.ConfigParser()


    def readConfig(self):
        """
        1. 读取配置文件
        """
        # 读取 stopWord.conf 配置文件
        self.cf.read(self.filePath)


        # 获取 stopWordList
        stopWordList = self.cf["stop_word"]["stop_word"].split(",")

        # 返回 stopWordList
        return stopWordList