i'm querying database , archiving results using python, , i'm trying compress data write log files. i'm having problems it, though. my code looks this: log_file = codecs.open(archive_file, 'w', 'bz2') id, f1, f2, f3 in cursor: log_file.write('%s %s %s %s\n' % (id, f1 or 'null', f2 or 'null', f3)) however, output file has size of 1,409,780. running bunzip2 on file results in file size of 943,634, , running bzip2 on results in size of 217,275. in other words, uncompressed file smaller file compressed using python's bzip codec. is there way fix this, other running bzip2 on command line? i tried python's gzip codec (changing line codecs.open(archive_file, 'a+', 'zip') ) see if fixed problem. still large files, gzip: archive_file: not in gzip format error when try uncompress file. what's going on there? edit : had file opened in append mode, not write mode. while may or may not pro...