From 5eb1b262283b07ddfe7df5d9c4b57e62dfd66b26 Mon Sep 17 00:00:00 2001 From: Florian Heiderich Date: Sun, 14 Jul 2019 14:34:04 +0200 Subject: [PATCH 1/2] do not open file in binary mode --- cms50dplus/cms50dplus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cms50dplus/cms50dplus.py b/cms50dplus/cms50dplus.py index 82e2920..91a0286 100755 --- a/cms50dplus/cms50dplus.py +++ b/cms50dplus/cms50dplus.py @@ -289,7 +289,7 @@ def dumpLiveData(port, filename): print "Press CTRL-C or disconnect the device to terminate data collection." oximeter = CMS50Dplus(port) measurements = 0 - with open(filename, 'wb') as csvfile: + with open(filename, 'w') as csvfile: writer = csv.writer(csvfile, quoting=csv.QUOTE_NONNUMERIC) writer.writerow(LiveDataPoint.getCsvColumns()) for liveData in oximeter.getLiveData(): @@ -311,7 +311,7 @@ def dumpRecordedData(starttime, port, filename): print "Please wait as the latest session is downloaded..." oximeter = CMS50Dplus(port) measurements = 0 - with open(filename, 'wb') as csvfile: + with open(filename, 'w') as csvfile: writer = csv.writer(csvfile, quoting=csv.QUOTE_NONNUMERIC) writer.writerow(RecordedDataPoint.getCsvColumns()) for recordedData in oximeter.getRecordedData(starttime): From 8362c8bc3052e1525a765eb71bb19a7c9e46963c Mon Sep 17 00:00:00 2001 From: Florian Heiderich Date: Sun, 14 Jul 2019 14:35:59 +0200 Subject: [PATCH 2/2] use parenthesis for "print" for compatibility with python3 --- cms50dplus/cms50dplus.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cms50dplus/cms50dplus.py b/cms50dplus/cms50dplus.py index 91a0286..b77876f 100755 --- a/cms50dplus/cms50dplus.py +++ b/cms50dplus/cms50dplus.py @@ -111,7 +111,7 @@ def getDictData(self): class RecordedDataPoint(object): def __init__(self, time, data): if data[0] & 0xfe != 0xf0 or data[1] & 0x80 == 0 or data[2] & 0x80 != 0: - print data + print(data) raise ValueError("Invalid data packet.") self.time = time @@ -266,7 +266,7 @@ def getRecordedData(self, time): m = int(s / 60) s -= m * 60 - print "Number of measurements: {0} ({1}h{2}m{3}s)".format(length / 3, h, m, s) + print("Number of measurements: {0} ({1}h{2}m{3}s)".format(length / 3, h, m, s)) # Content... packet = [0]*3 @@ -285,8 +285,8 @@ def getRecordedData(self, time): self.disconnect() def dumpLiveData(port, filename): - print "Saving live data..." - print "Press CTRL-C or disconnect the device to terminate data collection." + print("Saving live data...") + print("Press CTRL-C or disconnect the device to terminate data collection.") oximeter = CMS50Dplus(port) measurements = 0 with open(filename, 'w') as csvfile: @@ -307,8 +307,8 @@ def getLiveData(port, framerate=None): def dumpRecordedData(starttime, port, filename): - print "Saving recorded data..." - print "Please wait as the latest session is downloaded..." + print("Saving recorded data...") + print("Please wait as the latest session is downloaded...") oximeter = CMS50Dplus(port) measurements = 0 with open(filename, 'w') as csvfile: @@ -341,7 +341,7 @@ def valid_datetime(s): elif args.mode == 'RECORDED' and args.starttime is not None: dumpRecordedData(args.starttime, args.serialport, args.output) else: - print "Missing start time for RECORDED mode." + print("Missing start time for RECORDED mode.") - print "" - print "Done." \ No newline at end of file + print("") + print("Done.")