File size: 587 Bytes
d56c551 | 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 | import sys
import os
import os.path as osp
from pathlib import Path
import pickle
def get_object(name):
if getattr(sys, 'frozen', False):
base_dir = sys._MEIPASS
else:
base_dir = Path(__file__).parent.absolute()
objects_dir = osp.join(base_dir, 'objects')
if not name.endswith('.pkl'):
name = name + ".pkl"
filepath = osp.join(objects_dir, name)
if not osp.exists(filepath):
print(f"[Error] File not found: {filepath}")
return None
with open(filepath, 'rb') as f:
obj = pickle.load(f)
return obj
|