forked from xdarov/PiscinePythonDataScience
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst_constructor.py
More file actions
36 lines (28 loc) · 940 Bytes
/
Copy pathfirst_constructor.py
File metadata and controls
36 lines (28 loc) · 940 Bytes
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
import sys
class Research:
def __init__(self, file_name: str) -> None:
self.file_name = file_name
def check_struct(self, data: str) -> bool:
data = data.split('\n')
for i, value in enumerate(data):
value = value.strip().split(',')
if len(value) != 2:
raise ValueError('Bad Struct of file')
elif i > 0 and ('0' not in value or '1' not in value):
raise ValueError('Bad Struct of file')
def file_reader(self):
try:
with open(self.file_name, 'r') as file:
data = file.read()
self.check_struct(data)
return data
except (OSError, ValueError) as e:
print('Exception: ', e)
def main():
obj = Research(sys.argv[1])
data = obj.file_reader()
if data != None:
print(data)
if __name__ == '__main__':
if len(sys.argv) == 2:
main()