On Thu, Jun 18, 2015 at 10:38 PM, <random...@fastmail.us> wrote: > On Wed, Jun 17, 2015, at 20:23, Chris Angelico wrote: >> On Thu, Jun 18, 2015 at 7:55 AM, Paul Hubert <phbr...@gmail.com> wrote: >> > f_in = open(dafile, 'rb') >> > f_out = gzip.open('/Users/Paul/Desktop/scripts/pic.jpg.gz', 'wb') >> > f_out.writelines(f_in) >> > f_out.close() >> > f_in.close() >> >> Are you sure you want iteration and writelines() here? I would be >> inclined to avoid those for any situation that isn't plain text. If >> the file isn't too big, I'd just read it all in a single blob and then >> write it all out at once. > > Is there a reason not to use shutil.copyfileobj?
If the file is too big (or might be too big) to want to fit into memory, then sure. But a typical JPEG image isn't going to be gigabytes of content; chances are it's going to be a meg or so at most, and that doesn't justify the overhead of chunking. Just read it, write it, job done. ChrisA -- https://mail.python.org/mailman/listinfo/python-list