Skip to content

Commit b51b995

Browse files
Merge pull request #12 from jkrueger1/master
Make print statements python3 compatible
2 parents ed8e029 + c16fcc3 commit b51b995

3 files changed

Lines changed: 35 additions & 33 deletions

File tree

nxs/tree.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@
236236
signal sample points, entry is file/path within the file to the data group and
237237
title is the title of the group or the parent NXentry, if available.
238238
"""
239-
from __future__ import with_statement
239+
from __future__ import absolute_import, with_statement, print_function
240240
from copy import copy, deepcopy
241241

242242
import numpy as np
243-
import napi
244-
from napi import NeXusError
243+
import nxs.napi as napi
244+
from nxs.napi import NeXusError
245245

246246
#Memory in MB
247247
NX_MEMORY = 500
@@ -792,7 +792,7 @@ def dir(self,attrs=False,recursive=False):
792792
displayed. If 'recursive' is True, the contents of child groups are
793793
also displayed.
794794
"""
795-
print self._str_tree(attrs=attrs,recursive=recursive)
795+
print(self._str_tree(attrs=attrs,recursive=recursive))
796796

797797
@property
798798
def tree(self):
@@ -1823,7 +1823,7 @@ def plot(self, signal, axes, title, errors, fmt,
18231823
for _dim in data.shape[2:]:
18241824
slab.append(0)
18251825
data = data[slab].view().reshape(data.shape[:2])
1826-
print "Warning: Only the top 2D slice of the data is plotted"
1826+
print("Warning: Only the top 2D slice of the data is plotted")
18271827

18281828
x = axis_data[0]
18291829
y = axis_data[1]
@@ -3240,7 +3240,7 @@ def demo(argv):
32403240
ls *.nxs
32413241
plot file.nxs entry.data
32423242
"""%(argv[0],)
3243-
print usage
3243+
print(usage)
32443244

32453245

32463246
if __name__ == "__main__":

nxs/unit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __init__(self,name):
162162
else:
163163
self.scalemap = {'': 1}
164164
self.scalebase = 1
165-
#raise ValueError, "Unknown unit %s"%name
165+
#raise ValueError("Unknown unit %s"%name)
166166

167167
def scale(self, units=""):
168168
if units == "" or self.scalemap is None: return 1
@@ -181,7 +181,7 @@ def __call__(self, value, units=""):
181181
raise KeyError("%s not in %s"%(units," ".join(self.scalemap.keys())))
182182

183183
def _check(expect,get):
184-
if expect != get: raise ValueError, "Expected %s but got %s"%(expect,get)
184+
if expect != get: raise ValueError("Expected %s but got %s"%(expect,get))
185185
#print expect,"==",get
186186

187187
def test():

nxstest.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
NeXus tests converted to python.
77
"""
88

9+
from __future__ import print_function
10+
911
import nxs,os,numpy,sys
1012

1113
def memfootprint():
1214
import gc
1315
objs = gc.get_objects()
1416
classes = set( c.__class__ for c in gc.get_objects() if hasattr(c,'__class__') )
15-
# print "\n".join([c.__name__ for c in classes])
16-
print "#objects=",len(objs)
17-
print "#classes=",len(classes)
17+
# print("\n".join([c.__name__ for c in classes]))
18+
print("#objects=",len(objs))
19+
print("#classes=",len(classes))
1820

1921
def leak_test1(n = 1000, mode='w5'):
2022
# import gc
@@ -25,10 +27,10 @@ def leak_test1(n = 1000, mode='w5'):
2527
except OSError: pass
2628
file = nxs.open(filename,mode)
2729
file.close()
28-
print "File should exist now"
30+
print("File should exist now")
2931
for i in range(n):
3032
if i%100 == 0:
31-
print "loop count %d"%i
33+
print("loop count %d"%i)
3234
memfootprint()
3335
file.open()
3436
file.close()
@@ -39,31 +41,31 @@ def _show(file, indent=0):
3941
prefix = ' '*indent
4042
link = file.link()
4143
if link:
42-
print "%(prefix)s-> %(link)s" % locals()
44+
print("%(prefix)s-> %(link)s" % locals())
4345
return
4446
for attr,value in file.attrs():
45-
print "%(prefix)s@%(attr)s: %(value)s" % locals()
47+
print("%(prefix)s@%(attr)s: %(value)s" % locals())
4648
for name,nxclass in file.entries():
4749
if nxclass == "SDS":
4850
shape,dtype = file.getinfo()
4951
dims = "x".join([str(x) for x in shape])
50-
print "%(prefix)s%(name)s %(dtype)s %(dims)s" % locals()
52+
print("%(prefix)s%(name)s %(dtype)s %(dims)s" % locals())
5153
link = file.link()
5254
if link:
53-
print " %(prefix)s-> %(link)s" % locals()
55+
print(" %(prefix)s-> %(link)s" % locals())
5456
else:
5557
for attr,value in file.attrs():
56-
print " %(prefix)s@%(attr)s: %(value)s" % locals()
58+
print(" %(prefix)s@%(attr)s: %(value)s" % locals())
5759
if numpy.prod(shape) < 8:
5860
value = file.getdata()
59-
print " %s%s"%(prefix,str(value))
61+
print(" %s%s"%(prefix,str(value)))
6062
else:
61-
print "%(prefix)s%(name)s %(nxclass)s" % locals()
63+
print("%(prefix)s%(name)s %(nxclass)s" % locals())
6264
_show(file, indent+2)
6365

6466
def show_structure(filename):
6567
file = nxs.open(filename)
66-
print "=== File",file.inquirefile()
68+
print("=== File",file.inquirefile())
6769
_show(file)
6870

6971

@@ -168,7 +170,7 @@ def populate(filename,mode):
168170
failures = 0
169171
def fail(msg):
170172
global failures
171-
print "FAIL:",msg
173+
print("FAIL:",msg)
172174
failures += 1
173175

174176
def dicteq(a,b):
@@ -177,14 +179,14 @@ def dicteq(a,b):
177179
"""
178180
for k,v in a.iteritems():
179181
if k not in b:
180-
print k,"not in",b
182+
print(k,"not in",b)
181183
return False
182184
if v != b[k]:
183-
print v,"not equal",b[k]
185+
print(v,"not equal",b[k])
184186
return False
185187
for k,v in b.iteritems():
186188
if k not in a:
187-
print k,"not in",a
189+
print(k,"not in",a)
188190
return False
189191
return True
190192

@@ -264,10 +266,10 @@ def check(filename, mode):
264266
fail("returned string array info is incorrect")
265267
if not (rawshape[0]==5 and rawshape[1]==4 and rawdtype=='char'):
266268
fail("returned string array storage info is incorrect")
267-
print rawshape,dtype
269+
print(rawshape,dtype)
268270
if not (get[0]=="abcd" and get[4]=="qrst"):
269271
fail("returned string is incorrect")
270-
print shape,dtype
272+
print(shape,dtype)
271273

272274

273275
# Check reading from compressed datasets
@@ -281,7 +283,7 @@ def check(filename, mode):
281283
file.closegroup() #/entry/data
282284
if not (get == expected).all():
283285
fail("compressed data differs")
284-
print get
286+
print(get)
285287

286288
# Check strings
287289
file.opengroup('sample','NXsample') #/entry/sample
@@ -293,13 +295,13 @@ def check(filename, mode):
293295
file.closegroup() #/entry/sample
294296
if not (shape[0]==12 and dtype=='char'):
295297
fail("returned string info is incorrect")
296-
print shape,dtype
298+
print(shape,dtype)
297299
if not (rawshape[0]==20 and rawdtype=='char'):
298300
fail("returned string storage info is incorrect")
299-
print shape,dtype
301+
print(shape,dtype)
300302
if not (get == "NeXus sample"):
301303
fail("returned string is incorrect")
302-
print shape,dtype
304+
print(shape,dtype)
303305

304306
file.closegroup() #/entry
305307

@@ -328,13 +330,13 @@ def check(filename, mode):
328330
expected = comp_array[4:(4+5),4:(4+3)]
329331
if not (get == expected).all():
330332
fail("retrieved compressed slabs differ")
331-
print get
333+
print(get)
332334
file.openpath('/entry/data/comp_data')
333335
get = file.getslab([4,4],[5,3])
334336
expected = comp_array[4:(4+5),4:(4+3)]
335337
if not (get == expected).all():
336338
fail("after reopen: retrieved compressed slabs differ")
337-
print get
339+
print(get)
338340
file.openpath('../r8_data')
339341
for k,v in file.attrs():
340342
if k == 'target' and v != '/entry/r8_data':

0 commit comments

Comments
 (0)