From c5dd0f4f634047b2ff85d8e1268197d82283609f Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sat, 12 Jan 2013 14:35:32 -0500 Subject: [PATCH] Fixed print statements for python 3 --- examples/__main__.py | 1 + examples/multiprocess.py | 32 +++++++++++++------------- examples/parallelize.py | 12 +++++----- pyqtgraph/debug.py | 8 +++---- pyqtgraph/exporters/SVGExporter.py | 2 +- pyqtgraph/flowchart/library/Data.py | 2 +- pyqtgraph/functions.py | 2 +- pyqtgraph/multiprocess/parallelizer.py | 4 ++-- pyqtgraph/multiprocess/processes.py | 4 ++-- pyqtgraph/multiprocess/remoteproxy.py | 22 +++++++++--------- pyqtgraph/opengl/glInfo.py | 8 +++---- pyqtgraph/reload.py | 12 +++++----- 12 files changed, 55 insertions(+), 54 deletions(-) diff --git a/examples/__main__.py b/examples/__main__.py index 87673208..d8456781 100644 --- a/examples/__main__.py +++ b/examples/__main__.py @@ -68,6 +68,7 @@ examples = OrderedDict([ ('GraphicsScene', 'GraphicsScene.py'), ('Flowcharts', 'Flowchart.py'), + ('Custom Flowchart Nodes', 'FlowchartCustomNode.py'), #('Canvas', '../canvas'), #('MultiPlotWidget', 'MultiPlotWidget.py'), ]) diff --git a/examples/multiprocess.py b/examples/multiprocess.py index f6756345..ba550f7f 100644 --- a/examples/multiprocess.py +++ b/examples/multiprocess.py @@ -8,32 +8,32 @@ import time -print "\n=================\nStart Process" +print("\n=================\nStart Process") proc = mp.Process() import os -print "parent:", os.getpid(), "child:", proc.proc.pid -print "started" +print("parent:", os.getpid(), "child:", proc.proc.pid) +print("started") rnp = proc._import('numpy') arr = rnp.array([1,2,3,4]) -print repr(arr) -print str(arr) -print "return value:", repr(arr.mean(_returnType='value')) -print "return proxy:", repr(arr.mean(_returnType='proxy')) -print "return auto: ", repr(arr.mean(_returnType='auto')) +print(repr(arr)) +print(str(arr)) +print("return value:", repr(arr.mean(_returnType='value'))) +print( "return proxy:", repr(arr.mean(_returnType='proxy'))) +print( "return auto: ", repr(arr.mean(_returnType='auto'))) proc.join() -print "process finished" +print( "process finished") -print "\n=================\nStart ForkedProcess" +print( "\n=================\nStart ForkedProcess") proc = mp.ForkedProcess() rnp = proc._import('numpy') arr = rnp.array([1,2,3,4]) -print repr(arr) -print str(arr) -print repr(arr.mean()) +print( repr(arr)) +print( str(arr)) +print( repr(arr.mean())) proc.join() -print "process finished" +print( "process finished") @@ -42,10 +42,10 @@ import pyqtgraph as pg from pyqtgraph.Qt import QtCore, QtGui app = pg.QtGui.QApplication([]) -print "\n=================\nStart QtProcess" +print( "\n=================\nStart QtProcess") import sys if (sys.flags.interactive != 1): - print " (not interactive; remote process will exit immediately.)" + print( " (not interactive; remote process will exit immediately.)") proc = mp.QtProcess() d1 = proc.transfer(np.random.normal(size=1000)) d2 = proc.transfer(np.random.normal(size=1000)) diff --git a/examples/parallelize.py b/examples/parallelize.py index d2ba0ce0..768d6f00 100644 --- a/examples/parallelize.py +++ b/examples/parallelize.py @@ -5,7 +5,7 @@ import pyqtgraph.multiprocess as mp import pyqtgraph as pg import time -print "\n=================\nParallelize" +print( "\n=================\nParallelize") ## Do a simple task: ## for x in range(N): @@ -36,7 +36,7 @@ with pg.ProgressDialog('processing serially..', maximum=len(tasks)) as dlg: dlg += 1 if dlg.wasCanceled(): raise Exception('processing canceled') -print "Serial time: %0.2f" % (time.time() - start) +print( "Serial time: %0.2f" % (time.time() - start)) ### Use parallelize, but force a single worker ### (this simulates the behavior seen on windows, which lacks os.fork) @@ -47,8 +47,8 @@ with mp.Parallelize(enumerate(tasks), results=results2, workers=1, progressDialo for j in xrange(size): tot += j * x tasker.results[i] = tot -print "\nParallel time, 1 worker: %0.2f" % (time.time() - start) -print "Results match serial: ", results2 == results +print( "\nParallel time, 1 worker: %0.2f" % (time.time() - start)) +print( "Results match serial: %s" % str(results2 == results)) ### Use parallelize with multiple workers start = time.time() @@ -58,6 +58,6 @@ with mp.Parallelize(enumerate(tasks), results=results3, progressDialog='processi for j in xrange(size): tot += j * x tasker.results[i] = tot -print "\nParallel time, %d workers: %0.2f" % (mp.Parallelize.suggestedWorkerCount(), time.time() - start) -print "Results match serial: ", results3 == results +print( "\nParallel time, %d workers: %0.2f" % (mp.Parallelize.suggestedWorkerCount(), time.time() - start)) +print( "Results match serial: %s" % str(results3 == results)) diff --git a/pyqtgraph/debug.py b/pyqtgraph/debug.py index d5f86139..7fa169a4 100644 --- a/pyqtgraph/debug.py +++ b/pyqtgraph/debug.py @@ -393,7 +393,7 @@ class Profiler: if self.delayed: self.msgs.append(msg2) else: - print msg2 + print(msg2) self.t0 = ptime.time() self.t1 = self.t0 @@ -410,7 +410,7 @@ class Profiler: if self.delayed: self.msgs.append(msg2) else: - print msg2 + print(msg2) self.t1 = ptime.time() ## don't measure time it took to print def finish(self, msg=None): @@ -425,10 +425,10 @@ class Profiler: self.msgs.append(msg) if self.depth == 0: for line in self.msgs: - print line + print(line) Profiler.msgs = [] else: - print msg + print(msg) Profiler.depth = self.depth self.finished = True diff --git a/pyqtgraph/exporters/SVGExporter.py b/pyqtgraph/exporters/SVGExporter.py index 70f1f632..587282e0 100644 --- a/pyqtgraph/exporters/SVGExporter.py +++ b/pyqtgraph/exporters/SVGExporter.py @@ -220,7 +220,7 @@ def _generateItemSvg(item, nodes=None, root=None): ## get list of sub-groups g2 = [n for n in g1.childNodes if isinstance(n, xml.Element) and n.tagName == 'g'] except: - print doc.toxml() + print(doc.toxml()) raise diff --git a/pyqtgraph/flowchart/library/Data.py b/pyqtgraph/flowchart/library/Data.py index 85ab6232..1c612e08 100644 --- a/pyqtgraph/flowchart/library/Data.py +++ b/pyqtgraph/flowchart/library/Data.py @@ -236,7 +236,7 @@ class EvalNode(Node): text = fn + "\n".join([" "+l for l in str(self.text.toPlainText()).split('\n')]) + run exec(text) except: - print "Error processing node:", self.name() + print("Error processing node: %s" % self.name()) raise return output diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 00107927..27283631 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -798,7 +798,7 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False): if levels.shape != (data.shape[-1], 2): raise Exception('levels must have shape (data.shape[-1], 2)') else: - print levels + print(levels) raise Exception("levels argument must be 1D or 2D.") #levels = np.array(levels) #if levels.shape == (2,): diff --git a/pyqtgraph/multiprocess/parallelizer.py b/pyqtgraph/multiprocess/parallelizer.py index 2d03c000..c805cfdb 100644 --- a/pyqtgraph/multiprocess/parallelizer.py +++ b/pyqtgraph/multiprocess/parallelizer.py @@ -19,7 +19,7 @@ class Parallelize(object): for task in tasks: result = processTask(task) results.append(result) - print results + print(results) ## Here is the parallelized version: @@ -30,7 +30,7 @@ class Parallelize(object): for task in tasker: result = processTask(task) tasker.results.append(result) - print results + print(results) The only major caveat is that *result* in the example above must be picklable, diff --git a/pyqtgraph/multiprocess/processes.py b/pyqtgraph/multiprocess/processes.py index 1322e78e..1103ef15 100644 --- a/pyqtgraph/multiprocess/processes.py +++ b/pyqtgraph/multiprocess/processes.py @@ -232,7 +232,7 @@ class ForkedProcess(RemoteEventHandler): except ClosedError: break except: - print "Error occurred in forked event loop:" + print("Error occurred in forked event loop:") sys.excepthook(*sys.exc_info()) sys.exit(0) @@ -297,7 +297,7 @@ class QtProcess(Process): btn.show() def slot(): - print 'slot invoked on parent process' + print('slot invoked on parent process') btn.clicked.connect(proxy(slot)) # be sure to send a proxy of the slot """ diff --git a/pyqtgraph/multiprocess/remoteproxy.py b/pyqtgraph/multiprocess/remoteproxy.py index 94cc6048..887d2e87 100644 --- a/pyqtgraph/multiprocess/remoteproxy.py +++ b/pyqtgraph/multiprocess/remoteproxy.py @@ -68,7 +68,7 @@ class RemoteEventHandler(object): try: return cls.handlers[pid] except: - print pid, cls.handlers + print(pid, cls.handlers) raise def getProxyOption(self, opt): @@ -103,7 +103,7 @@ class RemoteEventHandler(object): else: raise except: - print "Error in process %s" % self.name + print("Error in process %s" % self.name) sys.excepthook(*sys.exc_info()) return numProcessed @@ -239,7 +239,7 @@ class RemoteEventHandler(object): self.send(request='result', reqId=reqId, callSync='off', opts=dict(result=result)) def replyError(self, reqId, *exc): - print "error:", self.name, reqId, exc[1] + print("error: %s %s %s" % (self.name, str(reqId), str(exc[1]))) excStr = traceback.format_exception(*exc) try: self.send(request='error', reqId=reqId, callSync='off', opts=dict(exception=exc[1], excString=excStr)) @@ -352,9 +352,9 @@ class RemoteEventHandler(object): try: optStr = pickle.dumps(opts) except: - print "==== Error pickling this object: ====" - print opts - print "=======================================" + print("==== Error pickling this object: ====") + print(opts) + print("=======================================") raise nByteMsgs = 0 @@ -404,12 +404,12 @@ class RemoteEventHandler(object): #print ''.join(result) exc, excStr = result if exc is not None: - print "===== Remote process raised exception on request: =====" - print ''.join(excStr) - print "===== Local Traceback to request follows: =====" + print("===== Remote process raised exception on request: =====") + print(''.join(excStr)) + print("===== Local Traceback to request follows: =====") raise exc else: - print ''.join(excStr) + print(''.join(excStr)) raise Exception("Error getting result. See above for exception from remote process.") else: @@ -535,7 +535,7 @@ class Request(object): raise ClosedError() time.sleep(0.005) if timeout >= 0 and time.time() - start > timeout: - print "Request timed out:", self.description + print("Request timed out: %s" % self.description) import traceback traceback.print_stack() raise NoResultError() diff --git a/pyqtgraph/opengl/glInfo.py b/pyqtgraph/opengl/glInfo.py index 95f59630..28da1f69 100644 --- a/pyqtgraph/opengl/glInfo.py +++ b/pyqtgraph/opengl/glInfo.py @@ -6,10 +6,10 @@ class GLTest(QtOpenGL.QGLWidget): def __init__(self): QtOpenGL.QGLWidget.__init__(self) self.makeCurrent() - print "GL version:", glGetString(GL_VERSION) - print "MAX_TEXTURE_SIZE:", glGetIntegerv(GL_MAX_TEXTURE_SIZE) - print "MAX_3D_TEXTURE_SIZE:", glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE) - print "Extensions:", glGetString(GL_EXTENSIONS) + print("GL version:" + glGetString(GL_VERSION)) + print("MAX_TEXTURE_SIZE: %d" % glGetIntegerv(GL_MAX_TEXTURE_SIZE)) + print("MAX_3D_TEXTURE_SIZE: %d" % glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE)) + print("Extensions: " + glGetString(GL_EXTENSIONS)) GLTest() diff --git a/pyqtgraph/reload.py b/pyqtgraph/reload.py index b9459073..ccf83913 100644 --- a/pyqtgraph/reload.py +++ b/pyqtgraph/reload.py @@ -267,14 +267,14 @@ class A(object): object.__init__(self) self.msg = msg def fn(self, pfx = ""): - print pfx+"A class:", self.__class__, id(self.__class__) - print pfx+" %%s: %d" %% self.msg + print(pfx+"A class: %%s %%s" %% (str(self.__class__), str(id(self.__class__)))) + print(pfx+" %%s: %d" %% self.msg) class B(A): def fn(self, pfx=""): - print pfx+"B class:", self.__class__, id(self.__class__) - print pfx+" %%s: %d" %% self.msg - print pfx+" calling superclass.. (%%s)" %% id(A) + print(pfx+"B class:", self.__class__, id(self.__class__)) + print(pfx+" %%s: %d" %% self.msg) + print(pfx+" calling superclass.. (%%s)" %% id(A) ) A.fn(self, " ") """ @@ -294,7 +294,7 @@ class C(A): A.__init__(self, msg + "(init from C)") def fn(): - print "fn: %s" + print("fn: %s") """ open(modFile1, 'w').write(modCode1%(1,1))