def to_disk(self): if not path.exists(path.dirname(self.filepath)): makedirs(path.dirname(self.filepath)) with fopen(self.filepath, 'w') as fd: fd.write(self.to_json())
def ensure_directory_exists(dirpath): if not path.exists(dirpath): makedirs(dirpath)