Skip to content

Commit d80c7e2

Browse files
author
Alan Christie
committed
- open_file() now supports as_text
Part of RDKit/Python3 migration
1 parent 6443284 commit d80c7e2

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/python/pipelines_utils/utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ def round_sig(x, sig):
3232
return round(x, sig - int(floor(log10(abs(x)))) - 1)
3333

3434

35-
def open_file(filename):
36-
"""Open the file gunzipping it if it ends with .gz"""
35+
def open_file(filename, as_text=False):
36+
"""Open the file gunzipping it if it ends with .gz.
37+
If as_text the file is opened in text mode,
38+
otherwise the file's opened in binary mode."""
3739
if filename.lower().endswith('.gz'):
38-
return gzip.open(filename, 'rt')
40+
if as_text:
41+
return gzip.open(filename, 'rt')
42+
else:
43+
return gzip.open(filename, 'rb')
3944
else:
40-
return open(filename, 'r')
45+
if as_text:
46+
return open(filename, 'rt')
47+
else:
48+
return open(filename, 'rb')
4149

4250

4351
def create_simple_writer(outputDef, defaultOutput, outputFormat, fieldNames,

src/python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_long_description():
2222
setup(
2323

2424
name='im-pipelines-utils',
25-
version='2.4.4',
25+
version='2.4.5',
2626
author='Alan Christie',
2727
author_email='[email protected]',
2828
url='https://github.com/InformaticsMatters/pipelines-utils',

0 commit comments

Comments
 (0)