diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-01-28 03:19:25 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-01-28 03:19:25 +0300 |
commit | e49227975fd10e9f130f46116f905351c17167c4 (patch) | |
tree | c2b5f75a5e6a7ec5dbf4eaf080f46a96e3e29ac0 /bin/utils/output.py | |
parent | add abstract classes for db readers/writers (diff) | |
download | vk-scripts-e49227975fd10e9f130f46116f905351c17167c4.tar.gz vk-scripts-e49227975fd10e9f130f46116f905351c17167c4.zip |
refactoring
Diffstat (limited to '')
-rw-r--r-- | bin/utils/output.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/bin/utils/output.py b/bin/utils/output.py index 8954c8b..70c1a3a 100644 --- a/bin/utils/output.py +++ b/bin/utils/output.py @@ -8,7 +8,7 @@ import csv import json import sys -class OutputWriterJSON: +class FileWriterJSON: def __init__(self, fd=sys.stdout): self._fd = fd @@ -16,7 +16,7 @@ class OutputWriterJSON: self._fd.write(json.dumps(something, indent=3, ensure_ascii=False)) self._fd.write('\n') -class OutputWriterCSV: +class FileWriterCSV: def __init__(self, fd=sys.stdout): self._writer = csv.writer(fd, lineterminator='\n') @@ -24,8 +24,8 @@ class OutputWriterCSV: self._writer.writerow(row) @contextmanager -def _open_file(path=None, **kwargs): - fd = sys.stdout +def _open_file(path=None, default=None, **kwargs): + fd = default if path is None: pass else: @@ -36,8 +36,8 @@ def _open_file(path=None, **kwargs): if fd is not sys.stdout: fd.close() -def open_text_file(path=None): - return _open_file(path, mode='w', encoding='utf-8') +def open_output_text_file(path=None): + return _open_file(path, default=sys.stdout, mode='w', encoding='utf-8') -def open_binary_file(path=None): - return _open_file(path, mode='wb') +def open_output_binary_file(path=None): + return _open_file(path, default=sys.stdout, mode='wb') |