From 59cfbed523d905937f3a126742a6a61b8117c7ac Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 10 Sep 2014 20:39:46 -0500 Subject: [PATCH 1/2] Python3 fixes --- README.md | 2 +- messenger/make.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 75728d1..ae5c2f3 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ same name. For example, to call the function jk in jk.m: you would call: res = mlab.run_func('path/to/jk.m', {'arg1': 3, 'arg2': 5}) - print res['result'] + print(es['result']) This would print `8`. diff --git a/messenger/make.py b/messenger/make.py index cc35a94..fa686be 100755 --- a/messenger/make.py +++ b/messenger/make.py @@ -1,5 +1,5 @@ #!/usr/bin/python - +from __future__ import print_function import os import sys import fnmatch @@ -8,7 +8,7 @@ # Check the system platform first platform = sys.platform -print "This is a " + platform + " system" +print("This is a " + platform + " system") if platform.startswith('linux'): messenger_dir = 'mexa64' @@ -25,30 +25,30 @@ # Open the configure file and start parsing config = open(os.path.join(messenger_dir, 'local.cfg'), 'r') -for line in config: +for line in config.decode('utf-8'): path = line.split('=') if path[0] == "MATLAB_BIN": - print "Searching for Matlab bin folder in local.cfg ..." + print("Searching for Matlab bin folder in local.cfg ...") matlab_bin = path[1].rstrip('\r\n') if matlab_bin == "": raise ValueError("Could not find Matlab bin folder. Please add it to local.cfg") - print "Matlab found in " + matlab_bin + print("Matlab found in " + matlab_bin) elif path[0] == "HEADER_PATH": - print "Searching for zmq.h in local.cfg ..." + print("Searching for zmq.h in local.cfg ...") header_path = path[1].rstrip('\r\n') if header_path == "": raise ValueError("Could not find zmq.h. Please add its path to local.cfg") - print "zmq.h found in " + header_path + print("zmq.h found in " + header_path) elif path[0] == "LIB_PATH": - print "Searching for zmq library in local.cfg ..." + print("Searching for zmq library in local.cfg ...") lib_path = path[1].rstrip('\r\n') if lib_path == "": raise ValueError("Could not find zmq library. Please add its path to local.cfg") - print "zmq library found in " + lib_path + print("zmq library found in " + lib_path) config.close() @@ -62,7 +62,7 @@ check_extension = subprocess.Popen(extcmd, stdout = subprocess.PIPE) extension = check_extension.stdout.readline().rstrip('\r\n') -print "Building messenger." + extension + " ..." +print("Building messenger." + extension + " ...") # Build the mex file if platform == 'win32': From fd0b714cb54963d8606987f38f70514c9b88eb25 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 10 Sep 2014 20:52:51 -0500 Subject: [PATCH 2/2] Decode opened files --- pymatbridge/examples/pymatbridge.ipynb | 4 ++-- pymatbridge/matlab_magic.py | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pymatbridge/examples/pymatbridge.ipynb b/pymatbridge/examples/pymatbridge.ipynb index 8d29af9..17747cb 100644 --- a/pymatbridge/examples/pymatbridge.ipynb +++ b/pymatbridge/examples/pymatbridge.ipynb @@ -149,7 +149,7 @@ " display_data.append(('MatlabMagic.matlab',\n", " {'text/plain':text_output}))\n", "for imgf in imgfiles:\n", - " image = open(imgf[0], 'rb').read() \n", + " image = open(imgf[0], 'rb').read().decode('utf-8') \n", " display_data.append(('MatlabMagic.matlab', {'image/png': image}))\n", "\n", "for tag, disp_d in display_data:\n", @@ -257,4 +257,4 @@ "metadata": {} } ] -} \ No newline at end of file +} diff --git a/pymatbridge/matlab_magic.py b/pymatbridge/matlab_magic.py index 7d94e89..a57210c 100644 --- a/pymatbridge/matlab_magic.py +++ b/pymatbridge/matlab_magic.py @@ -235,7 +235,7 @@ def matlab(self, line, cell=None, local_ns=None): if len(imgf): # Store the path to the directory so that you can delete it # later on: - image = open(imgf, 'rb').read() + image = open(imgf, 'rb').read().decode('utf-8') if ipython_version < 3: display_data.append(('MatlabMagic.matlab', {'image/png':image})) diff --git a/setup.py b/setup.py index 4c55b21..b27a974 100755 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def copy_bin(bin_path): # Get version and release info, which is all stored in pymatbridge/version.py ver_file = os.path.join('pymatbridge', 'version.py') -exec(open(ver_file).read()) +exec(open(ver_file).read().decode('utf-8')) opts = dict(name=NAME, maintainer=MAINTAINER,