-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.py
More file actions
48 lines (42 loc) · 1.41 KB
/
helper.py
File metadata and controls
48 lines (42 loc) · 1.41 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
# module contains miscellaneous functions
class helper():
# function parses a string and converts to appropriate type
@staticmethod
def convert(value):
types = [int,float,str] # order needs to be this way
if value == '':
return None
for t in types:
try:
return t(value)
except:
pass
# function reads file path to clean up data file
@staticmethod
def data_cleaner(path):
with open(path,"r",encoding="utf-8") as f:
data = f.readlines()
data = [i.strip().split(",") for i in data]
data_cleaned = []
for row in data[:]:
row = [helper.convert(i) for i in row]
data_cleaned.append(tuple(row))
return data_cleaned
# function checks for user input given a list of choices
@staticmethod
def get_choice(lst):
choice = input("Enter choice number: ")
while choice.isdigit() == False:
print("Incorrect option. Try again")
choice = input("Enter choice number: ")
while int(choice) not in lst:
print("Incorrect option. Try again")
choice = input("Enter choice number: ")
return int(choice)
# function prints a list of strings nicely
@staticmethod
def pretty_print(lst):
print("Results..\n")
for i in lst:
print(i)
print("")