forked from OmerShubi/Reuters_1987_Classification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpickleHelper.py
More file actions
28 lines (19 loc) · 784 Bytes
/
pickleHelper.py
File metadata and controls
28 lines (19 loc) · 784 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
from datetime import datetime
import pickle
import logging.config
logger = logging.getLogger(__name__)
def save_to_pickle(file_name, data):
path = "Pickles/" + get_file_name_datetime(file_name)
pickle.dump(data, open(path, 'wb'))
logger.info("{} saved to {}".format(file_name, path))
def retrieve_from_pickle(path, file_name='unknown'):
try:
data = pickle.load(open(path, 'rb'))
except FileNotFoundError:
logger.exception("File not Found")
raise FileNotFoundError
else:
logger.info("Retrieved {} pickle from {} ".format(file_name, path))
return data
def get_file_name_datetime(prefix, suffix='', file_type='p'):
return prefix + "-" + str(datetime.now().strftime("%Y-%m-%d-%H%M")) + suffix + "." + file_type