forked from UM-LoCoLab/NeuroLocoMiddleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileGlobal.py
37 lines (29 loc) · 798 Bytes
/
FileGlobal.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
32
33
34
35
36
37
class FileGlobalInt():
def __init__(self, name, default=0):
self.name=name
try:
fil = open(name, 'r')
except FileNotFoundError:
fil = open(name, 'x')
with fil:
fil.write("%d"%default)
fil = open(name, 'r')
with fil:
self._datum = int(fil.read())
@property
def datum(self):
return self._datum
@datum.setter
def datum(self, value):
self._datum=value
with open(self.name, 'w') as fil:
fil.write("%d"%self._datum)
def test_integer():
x = FileGlobalInt("test_file_global_integer.txt")
print(x.datum)
x.datum+=1
print("%d"%x.datum)
x.datum=0
print("%d"%x.datum)
if __name__ == '__main__':
test_integer()