-
Notifications
You must be signed in to change notification settings - Fork 1
/
dm_config.py
31 lines (25 loc) · 967 Bytes
/
dm_config.py
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
import configparser
import os
exepath = os.getcwd()
exepath = os.path.join(exepath, "dm_config.ini")
config = configparser.ConfigParser()
config.read(exepath, encoding='utf-8-sig')
class ReadConfig:
@staticmethod
def get_dm(name):
value = 0
try:
value = config.get('dm', name) # 通过config.get拿到配置文件中DATABASE的name的对应值
except Exception as e:
value = -1
return value
if __name__ == '__main__':
print('config_path', exepath) # 打印输出config_path测试内容是否正确
print('通过config.get拿到配置文件中DATABASE的对应值\n',
'ip', ReadConfig().get_dm('ip'),
'port', ReadConfig().get_dm('port'),
'username', ReadConfig().get_dm('username'),
'password', ReadConfig().get_dm('password'),
'sqlpath', ReadConfig().get_dm('sqlpath'),
'tab_name', ReadConfig().get_dm('tab_name'),
)