Created
June 4, 2015 19:53
-
-
Save Hammer2900/b9ca29ed541e22983a5a to your computer and use it in GitHub Desktop.
Pickle class for save load object in file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PickleFileManager(object): | |
def __init__(self, homedir): | |
self.HOMED = homedir | |
self.dir_is_exsist() | |
def dir_is_exsist(self): | |
if os.path.exists(self.HOMED): | |
pass | |
else: | |
os.mkdir(self.HOMED) | |
def get_fullpath(self, name): | |
return "{path}/{name}".format(path=self.HOMED, name=name) | |
def save_conf(self, name, object_file): | |
with open(self.get_fullpath(name), 'wb') as conf_file: | |
pickle.dump(object_file, conf_file, pickle.HIGHEST_PROTOCOL) | |
def load_conf(self, name): | |
with open(self.get_fullpath(name), 'rb') as conf_file: | |
return pickle.load(conf_file) | |
def find_all_conf(self): | |
return [f for f in os.listdir(self.HOMED)] | |
if __name__ == '__main__': | |
fff = PickleFileManager('Date') | |
fff.save_conf('testo', fff) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment