From 5c747fe40450fc47808572d397f95656bf836d11 Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Thu, 12 Dec 2013 13:46:03 +0000 Subject: [PATCH] Tweaks to make things work on Python 2 --- BioLogic.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/BioLogic.py b/BioLogic.py index 12884d4..d83cdf8 100644 --- a/BioLogic.py +++ b/BioLogic.py @@ -3,6 +3,7 @@ __all__ = ['MPTfileCSV', 'MPTfile'] +import sys import re import csv from os import SEEK_SET, SEEK_CUR @@ -14,6 +15,12 @@ from warnings import warn import numpy as np +if sys.version_info.major <= 2: + str3 = str +else: + str3 = lambda b: str(b, encoding='ascii') + + def fieldname_to_dtype(fieldname): """Converts a column header from the MPT file into a tuple of canonical name and appropriate numpy dtype""" @@ -34,7 +41,7 @@ def fieldname_to_dtype(fieldname): return ("I/mA", np.float_) else: raise ValueError("Invalid column header: %s" % fieldname) - + def MPTfile(file_or_path): """Opens .mpt files as numpy record arrays @@ -152,7 +159,7 @@ def VMPdata_dtype_from_colIDs(colIDs): dtype_dict['(Q-Qo)/C'] = '