48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
# -*- coding: UTF-8 -*-
|
||
"""
|
||
@Project :onestar
|
||
@File :ConfigeHandle.py
|
||
@Contact:https://blog.csdn.net/songlh1234/article/details/83316468
|
||
@Author :SHJ
|
||
@Date :2021/11/23 16:57
|
||
@Version :1.0.0
|
||
"""
|
||
import os
|
||
import configparser
|
||
|
||
|
||
class Config:
|
||
"""读写初始化配置文件"""
|
||
def __init__(self):
|
||
pass
|
||
|
||
@staticmethod
|
||
def get(para_name, option='config', config_name='config.ini'):
|
||
config = configparser.ConfigParser()
|
||
config_path = os.path.join(os.getcwd(), config_name)
|
||
config.read(config_path, encoding='utf-8')
|
||
config.sections()
|
||
exe_name = config.get(option, para_name)
|
||
return exe_name
|
||
|
||
def get_list(self, para_name, option='config', config_name='config.ini'):
|
||
config = configparser.ConfigParser()
|
||
config_path = os.path.join(os.getcwd(), config_name)
|
||
config.read(config_path, encoding='utf-8')
|
||
config.sections()
|
||
str_name = config.get(option, para_name)
|
||
# 去除空格和回车
|
||
str_name = str(str_name).replace("\n", "").replace(' ', '') # 去除空格和回车
|
||
# 分割成lists
|
||
name_list = str_name.split(',')
|
||
return name_list
|
||
|
||
|
||
if __name__ == '__main__':
|
||
# c = Config()
|
||
# a = c.get('exe_name')
|
||
# b = bool(c.get('debug'))
|
||
# d = int(c.get('cover_threshold'))
|
||
# f = float(c.get('ndvi_threshold'))
|
||
|
||
print('done') |