diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-12-04 21:59:18 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-12-04 21:59:18 -0500 |
commit | c2d9c4ae0f59f848abc71c59866181fbf45f552b (patch) | |
tree | e564dedbfca9aeb21f13e01e7b0a650ae8e84d54 /qolab/file_utils/__init__.py | |
parent | 4ba322216a2e7c7dec1dba21f24d46ef0ba6ec0c (diff) | |
download | pyExpControl-c2d9c4ae0f59f848abc71c59866181fbf45f552b.tar.gz pyExpControl-c2d9c4ae0f59f848abc71c59866181fbf45f552b.zip |
added save table method
Diffstat (limited to 'qolab/file_utils/__init__.py')
-rw-r--r-- | qolab/file_utils/__init__.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/qolab/file_utils/__init__.py b/qolab/file_utils/__init__.py index 67e64c8..af92c47 100644 --- a/qolab/file_utils/__init__.py +++ b/qolab/file_utils/__init__.py @@ -69,3 +69,19 @@ def get_next_data_file(prefix, savepath, run_number=None, date_format='%Y%m%d', fname = os.path.join(savepath, f'{prefix}_{datestr}_f{run_number:05d}.{extention}') return(fname) +def save_table_with_header(fname, data, header='', comment_symbol='%', skip_headers_if_file_exist=False, item_format='e', item_separator='\t'): + # itemFormat examples: 'e', '.15e', 'f' + fname = filename2os_fname(fname) + file_exist_flag = os.path.exists(fname) + r, c = data.shape + item_format=str.join('', ['{', f':{item_format}', '}']) + with open(fname, 'a') as f: + if not skip_headers_if_file_exist: + for l in header: + f.write(f'{comment_symbol} {l}\n') + for r in data: + l=item_separator.join( map(item_format.format, r)) + f.write(l) + f.write('\n') + f.close() + |