Is it possible to compress program output within python to reduce output file's size?

家住魔仙堡 提交于 2019-12-12 05:49:51

问题


I have a program that returns rows of allowed arrays (as follows) which are stored in a file (say output.txt), using python program.py>output.txt on the windows 7 command line:

0 , 0 , 1 , 1 , 6
0 , 0 , 1 , 2 , 1
0 , 0 , 1 , 4 , 1
0 , 0 , 1 , 6 , 1
0 , 0 , 2 , 0 , 0

I later use output.txt as input for another program, which reads it row by row into an array. The output.txt file is about 1.5 GB. I can use 7-zip to reduce it to 33 MB.

I risk running out of memory for the larger output data sizes. I'm aware that we can read zipped files in Python so is it possible to get zipped outputs as well?

My program has multiple nested loops, so I can make a small zip file after a cycle in the innermost loop and append it to another which gradually becomes larger as the loop traverses ahead.

来源:https://stackoverflow.com/questions/46707020/is-it-possible-to-compress-program-output-within-python-to-reduce-output-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!