diff --git a/BioLogic.py b/BioLogic.py index d83cdf8..42ab601 100644 --- a/BioLogic.py +++ b/BioLogic.py @@ -68,7 +68,7 @@ def MPTfile(file_or_path): ## make three lines. Every additional line is a comment line. comments = [next(mpt_file) for i in range(nb_headers - 3)] - fieldnames = next(mpt_file).decode('ascii').strip().split('\t') + fieldnames = str3(next(mpt_file)).strip().split('\t') record_type = np.dtype(list(map(fieldname_to_dtype, fieldnames))) mpt_array = np.loadtxt(mpt_file, dtype=record_type) @@ -89,7 +89,7 @@ def MPTfileCSV(file_or_path): mpt_file = file_or_path magic = next(mpt_file) - if magic != 'EC-Lab ASCII FILE\n': + if magic.rstrip() != 'EC-Lab ASCII FILE': raise ValueError("Bad first line for EC-Lab file: '%s'" % magic) nb_headers_match = re.match('Nb header lines : (\d+)\s*$', next(mpt_file)) @@ -248,8 +248,10 @@ class MPRfile: raise ValueError("Unrecognised version for data module: %d" % data_module['version']) - for empty_byte in remaining_headers: - assert(empty_byte == b'\x00') + if sys.version_info.major <= 2: + assert(all((b == '\x00' for b in remaining_headers))) + else: + assert(not any(remaining_headers)) self.dtype = VMPdata_dtype_from_colIDs(column_types) self.data = np.fromstring(main_data, dtype=self.dtype) diff --git a/tests/test_BioLogic.py b/tests/test_BioLogic.py index ffa06f7..51e2f94 100644 --- a/tests/test_BioLogic.py +++ b/tests/test_BioLogic.py @@ -8,8 +8,8 @@ import numpy as np from numpy.testing import assert_array_almost_equal, assert_array_equal from nose.tools import ok_, eq_, raises -from ..import MPTfile, MPRfile -from ..BioLogic import MPTfileCSV # not exported +from .. import MPTfile, MPRfile +from ..BioLogic import MPTfileCSV, str3 # not exported testdata_dir = os.path.join(os.path.dirname(__file__), 'testdata') @@ -93,7 +93,7 @@ def timestamp_from_comments(comments): for line in comments: time_match = re.match(b'Acquisition started on : ([0-9/]+ [0-9:]+)', line) if time_match: - timestamp = datetime.strptime(str(time_match.group(1), encoding='ascii'), + timestamp = datetime.strptime(str3(time_match.group(1)), '%m/%d/%Y %H:%M:%S') return timestamp raise AttributeError("No timestamp in comments")