-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingParser.py
More file actions
51 lines (38 loc) · 1.18 KB
/
SettingParser.py
File metadata and controls
51 lines (38 loc) · 1.18 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
class SettingParser:
filePath='./info.txt'
def read(self):
f = open(self.filePath, 'r')
info = dict()
lines = f.readlines()
for line in lines:
if not line: continue
if '=' not in line: continue
if '#' == line[0]: continue
key = line.split('=')[0]
data = line.split('=')[1].split(';')[0]
info[key] = data
f.close()
return info
def write(self, info):
f = open(self.filePath, 'r')
lines = f.readlines()
f.close()
f = open(self.filePath, 'w')
for line in lines:
if not line or '=' not in line or '#' == line[0]:
f.write(line)
continue
key = line.split('=')[0]
data = line.split('=')[1].split(';')[0]
if key in info:
line = key + '=' + info[key] + ';' + '\n'
print (line)
f.write(line)
f.close()
if __name__ == '__main__':
settingParser = SettingParser()
data = settingParser.read();
print(data)
data['SSID']='newSSID'
print(data)
settingParser.write(data)