aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-05-23 05:25:35 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-05-23 05:25:35 +0300
commita027e88fb7c6b12070ee86d740acb6bd42d29f0f (patch)
treee00bf1960c83ec1a19dd23b099b888c4cb0af06a
parentREADME update (diff)
downloadvk-scripts-a027e88fb7c6b12070ee86d740acb6bd42d29f0f.tar.gz
vk-scripts-a027e88fb7c6b12070ee86d740acb6bd42d29f0f.zip
bugfix
-rw-r--r--bin/utils/io.py11
-rw-r--r--vk/tracking/db/io.py11
2 files changed, 6 insertions, 16 deletions
diff --git a/bin/utils/io.py b/bin/utils/io.py
index 70c1a3a..2cd3667 100644
--- a/bin/utils/io.py
+++ b/bin/utils/io.py
@@ -25,16 +25,11 @@ class FileWriterCSV:
@contextmanager
def _open_file(path=None, default=None, **kwargs):
- fd = default
if path is None:
- pass
+ yield default
else:
- fd = open(path, **kwargs)
- try:
- yield fd
- finally:
- if fd is not sys.stdout:
- fd.close()
+ with open(path, **kwargs) as fd:
+ yield fd
def open_output_text_file(path=None):
return _open_file(path, default=sys.stdout, mode='w', encoding='utf-8')
diff --git a/vk/tracking/db/io.py b/vk/tracking/db/io.py
index d280634..487a136 100644
--- a/vk/tracking/db/io.py
+++ b/vk/tracking/db/io.py
@@ -25,16 +25,11 @@ class FileReaderCSV:
@contextmanager
def _open_file(path=None, default=None, **kwargs):
- fd = default
if path is None:
- pass
+ yield default
else:
- fd = open(path, **kwargs)
- try:
- yield fd
- finally:
- if fd is not default:
- fd.close()
+ with open(path, **kwargs) as fd:
+ yield fd
_DEFAULT_ENCODING = 'utf-8'