-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReader.py
More file actions
53 lines (45 loc) · 1.63 KB
/
FileReader.py
File metadata and controls
53 lines (45 loc) · 1.63 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 Reader:
"""This class have methods that
reads strings from different types of
measurements and stores them into lists.
"""
def __init__(self, filename, filepath = str()):
self.filename = filename
self.filepath = filepath
self.idata = []
# self.data = []
def readIV(self):
"""This method is tuned to IV data"""
with open(self.filepath + self.filename) as file:
properties = file.readline()
properties = properties.split()
lines = file.readlines()
v = []
i = []
for line in lines:
v.append(abs(float(line.split()[0])))
i.append(float(line.split()[1]))
self.idata.append(v)
self.idata.append(i)
return v,i
def __str__(self):
"""This special method previews the first and the last stored current values
by printing the initiated object of this class. This is made to give an
idea if the file is the correct one
"""
return f"The first and the last Current values measure are: {self.idata[1][0]} and {self.idata[1][-1]}"
def __add__(self, other):
"""returns combined data """
combined = [self.idata[0] + other.idata[0], self.idata[1] + other.idata[1]]
return combined
def readCV(self):
with open(self.filename) as file:
lines = file.readlines()
Vr = []
C = []
for line in lines:
Vr.append(float(line.split()[0]))
C.append(float(line.split()[1]))
return Vr, C
if __name__ == "__main__":
pass