Skip to content

Instantly share code, notes, and snippets.

View lglista's full-sized avatar
🤠

Lawrence Glista lglista

🤠
View GitHub Profile
@lglista
lglista / load_structure_from_file.py
Last active August 30, 2021 14:33
Python 3.8+ Save and Load objects from file
import pickle # https://docs.python.org/3/library/pickle.html
def load_structure_from_file(filename, structure):
"""Return an object saved in a file. Does not guarantee that the object returned is the same type as structure.
Return a default constructed structure if it could not load an object from the file.
Keyword Arguments:
filename -- the file to open. Full paths work the best
structure -- the data structure to return if the file could not be loaded. Must have a default constructor.
"""