aboutsummaryrefslogtreecommitdiff
path: root/qolab
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-06-19 23:58:25 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-06-19 23:58:25 -0400
commitbe0ba8b3d2c1e52fc0fc8c0de632e4dd6bf2939a (patch)
tree4e7b28349564697868711f1c42f3c5f7c23d9f53 /qolab
parent9d09be14fed200ac29ae467294fb46f8f1cfcfd6 (diff)
downloadqolab-be0ba8b3d2c1e52fc0fc8c0de632e4dd6bf2939a.tar.gz
qolab-be0ba8b3d2c1e52fc0fc8c0de632e4dd6bf2939a.zip
added ability to save with bzip compression
Diffstat (limited to 'qolab')
-rw-r--r--qolab/file_utils/__init__.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/qolab/file_utils/__init__.py b/qolab/file_utils/__init__.py
index 456fc2f..849718d 100644
--- a/qolab/file_utils/__init__.py
+++ b/qolab/file_utils/__init__.py
@@ -81,8 +81,11 @@ def save_table_with_header(fname, data, header='', comment_symbol='%', skip_head
_open = open # standard file handler
if compressionmethod == 'gzip':
import gzip
- _open = lambda fname, mode: gzip.open( fname, mode, compresslevel = compresslevel)
- with _open(fname, 'ab') as f:
+ _open = lambda fname, mode: gzip.open( fname, mode=mode, compresslevel = compresslevel)
+ if compressionmethod == 'bzip':
+ import bz2
+ _open = lambda fname, mode: bz2.open( fname, mode=mode, compresslevel = compresslevel)
+ with _open(fname, mode='ab') as f:
if not (file_exist_flag and skip_headers_if_file_exist):
for l in header:
f.write(f'{comment_symbol} {l}\n'.encode('utf-8'))