fumitoh / modelx

Use Python like a spreadsheet!

Home Page:https://modelx.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Zip archiving the folder

fumitoh opened this issue · comments

One more thing as we are talking about model saving. Have you thought about zip archiving the folder? It will save space and make it more convenient to send the model around. We save the model on OneDrive cloud and it ends up syncing a hundered files instead of 1.
Using zip archive will be the same as what Excel does with its files.
I can also implement this myself.

Originally posted by @alebaran in #32 (comment)

Good idea. Looks easy to implement and practical.

import shutil
save_name = 'my_model'
# write model
mx.write_model(model, save_name)
# zip
shutil.make_archive(save_name, 'zip', save_name)
shutil.rmtree(save_name)
# unzip
shutil.unpack_archive(save_name + '.zip', extract_dir='temp')
# read model
model = mx.read_model('temp')
shutil.rmtree('temp')

Thanks for the code.

Thank you for the quick release, very helpful. One question: do you intentionally zip archive without any compression?

I wasn’t paying attention to compression. But I did try to write directly to the zip file using zipfile and in-memory files to avoid writing files to the disk.

ZipFile() seems to have compression parameter, which is defaulted to no compression. Here is one of the options making it compress: compression=zipfile.ZIP_DEFLATED