-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileprocessing.py
47 lines (31 loc) · 1.05 KB
/
fileprocessing.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
# This module is in charge of managing files
import csv
import json
from pathlib import Path
import os
home = Path(__file__).parents[0]
def read_csv(filename):
list_file = []
with open(home / filename, 'r', encoding="utf-8-sig") as f:
reader = csv.reader(f, delimiter=';')
list_file = list(reader)
return list_file
def write_csv(filename, list_file):
while True:
try:
output = open(home / filename, 'w', newline='', encoding='utf-8-sig')
break
except PermissionError:
input("Please close the file: " + filename + " and click enter!")
output_writer = csv.writer(output, delimiter=';')
for i in list_file:
output_writer.writerow(i)
output.close()
#write configuration information
def read_json():
with open(home / 'config.json') as json_data_file:
data = json.load(json_data_file)
return data
def write_json(data):
with open(home / 'config.json', 'w') as outfile:
json.dump(data, outfile)