-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_functions_module.py
54 lines (35 loc) · 1.04 KB
/
file_functions_module.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import csv
import numpy as np
# functions for file operations
def file_2_list(file, character: str):
array = [[]]
# array.append([])
index = 0
for element in file.read().split(f"{character}"):
if '\n' in element:
tmp = element.split('\n')
array[index].append(tmp[0])
array.append([])
index += 1
array[index].append(tmp[1])
else:
array[index].append(element)
file.close()
return array
def show_list(list):
return np.array(list)
def list_2_file(list, file):
csv_writer = csv.writer(open(file, 'w'))
csv_writer.writerows(list)
# file.close()
def str_2_float_list(list):
for element in list:
for i in range(1, len(element)):
element[i] = float(element[i])
def file_2_dict(file, character: str):
tmp_dict = {}
tmp_array = file_2_list(open(file, 'r'), character)
str_2_float_list(tmp_array)
for element in tmp_array:
tmp_dict[element[0]] = element[0:]
return tmp_dict