-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateFile.py
More file actions
60 lines (48 loc) · 1.36 KB
/
Copy pathupdateFile.py
File metadata and controls
60 lines (48 loc) · 1.36 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# coding=utf8
import configparser
configfile = "config.ini"
class Update_Read_Config:
def __init__(self):
"""
初始化config实例
"""
self.cf = configparser.ConfigParser()
self.cf.read(configfile)
def read(self, n):
"""
:param n: 状态码
:return: 返回特定符合码的列表
"""
rule = []
sections = self.cf.sections()
for section in sections:
if self.cf.getint(section, "status") == n:
items = dict(self.cf.items(section))
rule.append({section: items})
return rule
def read_all(self):
rule = []
sections = self.cf.sections()
for section in sections:
items = dict(self.cf.items(section))
rule.append(items)
return rule
def read_sections(self):
"""
返回配置文件里面所有的sections
:return:
"""
sections = self.cf.sections()
return sections
# def read_key(self):
# self.read_sections(
def update(self, section, n):
"""
更新ini文件
:param section: 更新的节点
:param n: 更新的值
:return: 不返回,不做判断
"""
self.cf.set(section, "status", n)
with open(configfile, "w") as f:
self.cf.write(f)