-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadConfig.py
More file actions
30 lines (22 loc) · 1.31 KB
/
readConfig.py
File metadata and controls
30 lines (22 loc) · 1.31 KB
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
import os
import configparser
import frozen_dir
import getpathInfo # 引入我们自己的写的获取路径的类
path = getpathInfo.get_path() # 获取当前文件绝对路径
config_path = os.path.join(path, 'config.ini') # 获取配置文件的绝对路径
config = configparser.ConfigParser() # 调用外部的读取配置文件的方法
config.read(config_path, encoding='utf-8') # 以utf-8编码读取配置文件
class ReadConfig:
def get_http(self, name): # 定义获取配置文件中session为http的配置内容
value = config.get('HTTP', name) # 获取session为HTTP,key为‘name’的配置内容
return value # 返回获取到的配置内容
def get_email(self, name):
value = config.get('EMAIL', name) # 获取session为EMAIL,key为‘name’的配置内容
return value
def get_mysql(self, name): # 写好,留以后备用。因为我们没有对数据库的操作,所以这个可以屏蔽掉
value = config.get('DATABASE', name)
return value
if __name__ == '__main__': # 测试一下,我们读取配置文件的方法是否可用
'''print('HTTP中的baseurl值为:', ReadConfig().get_http('baseurl'))
print('EMAIL中的开关on_off值为:', ReadConfig().get_email('recv'))
print(type(ReadConfig().get_email('recv')))'''