-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilehelper.py
More file actions
40 lines (34 loc) · 1.04 KB
/
filehelper.py
File metadata and controls
40 lines (34 loc) · 1.04 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
import pickle
import json
class FileHelper:
@staticmethod
def read_data_lower(filename, encoding='UTF-8'):
"""Reads the text data from the given file and returns the content with lower case
"""
return open(file=filename, mode='r', encoding=encoding).read().lower()
@staticmethod
def write_data(filename, data):
"""Writes the text data to the given file
"""
open(file=filename, mode='w').write(data)
@staticmethod
def save_object_to_file(filename, obj):
"""Saves an object to a file
"""
with open(file=filename, mode='wb') as f:
pickle.dump(obj, f)
return
@staticmethod
def load_object_from_file(filename):
"""Loads an object from a file
"""
with open(file=filename, mode='rb') as f:
obj = pickle.load(f)
return obj
return
@staticmethod
def load_config(filename):
with open(filename) as f:
config = json.load(f)
return config
return ""