Also convert "'...' % (...)" to "'...'.format(...)".
These bring us up to date with Python 2.7, and will make future
porting to Python 3 less painful.
def main(*args):
if len(sys.argv) < 2:
- print 'You must at least specify origin and destination folders.'
+ print('You must at least specify origin and destination '
+ 'folders.')
return 0
origin=sys.argv[1]
dest=sys.argv[2]
if os.path.exists(origin):
if os.path.exists(dest):
if os.listdir(dest)!=[]:
- print 'Destination folder is not empty! Use another folder.'
+ print('Destination folder is not empty! Use '
+ 'another folder.')
return 0
else:
- print 'Destination folder does not exist, will create it'
+ print('Destination folder does not exist, will create '
+ 'it')
os.mkdir(dest)
else:
- print 'You provided a wrong origin folder name, try again.'
+ print('You provided a wrong origin folder name, try again.')
origin=os.path.abspath(origin)
dest=os.path.abspath(dest)
rawdest=rawdest.replace('/','') #for linux
rawdest=rawdest.replace('\\','') #for windows
destfile=os.path.join(dest,rawdest)
- print 'Copying '+rawdest
+ print('Copying '+rawdest)
shutil.copy(filepath,destfile)
return 0
try:
os.mkdir(exportdir)
except:
- print 'mkdir error, maybe the export directory already exists?'
+ print('mkdir error, maybe the export directory already exists?')
def h5exportfunc(name):
Deflname=name
notes=f[Deflname].attrs['IGORWaveNote']
springmatch=notes.index("SpringConstant: ")+len("SpringConstant: ")
springc=notes[springmatch:].split("\r",1)[0] #probably extracting the leading numbers can be way more elegant than this
- print Deflname
+ print(Deflname)
except:
- print 'Something bad happened with '+Deflname+', ignoring it'
+ print('Something bad happened with '+Deflname+
+ ', ignoring it')
return None
#returning anything but None halts the visit procedure
>>> p.info
{u'note': u'An example playlist'}
>>> for curve in p:
- ... print curve.path
+ ... print(curve.path)
path/to/curve/one
path/to/curve/two
>>> p[-1].info['attr with spaces']
if __name__ == '__main__':
if len(sys.argv) < 2:
- print >> sys.stderr, 'usage: upgrade_playlist_0p1.py X.hkp [Y.hkp ...]'
+ sys.stderr.write('usage: upgrade_playlist_0p1.py X.hkp [Y.hkp ...]\n')
sys.exit(1)
for path in sys.argv[1:]:
# Dump internals if debugging.
if debug:
- print "Environment:"
- print env.Dump()
+ print('Environment:')
+ print(env.Dump())
# Get parameters from Sphinx config file.
sphinxparams = {}
# Print banner if required.
if not any(map(GetOption, ("silent", "clean", "help"))):
- print
- print "This is", description
- print
+ print('')
+ print('This is {}'.format(description))
+ print('')
# Build sphinx command-line options.
opts = []
Serialize the tree with depth marking branches.
>>> for depth,node in a.thread():
- ... print "%*s" % (2*depth+1, node.n)
+ ... print('{}{}'.format(' '*2*depth, node.n))
a
b
d
branch splits.
>>> for depth,node in a.thread(flatten=True):
- ... print "%*s" % (2*depth+1, node.n)
+ ... print('{}{}'.format(' '*2*depth, node.n))
a
b
d
if __name__ == '__main__':
pt = python_tree(root_path='../hooke', root_modname='hooke')
for node in pt.traverse():
- print node.modname
+ print(node.modname)
make_module_txt(node.modname, [c.modname for c in node])
def put(self, item, block=True, timeout=None):
"""Print `item` and then dump it into the void.
"""
- print 'ITEM:\n%s' % item
+ print('ITEM:\n{}'.format(item))
>>> def execute_cmd(hooke, command_message, stack=None):
... cm = command_message
- ... print 'EXECUTE', cm.command, cm.arguments
+ ... print('EXECUTE {} {}'.format(cm.command, cm.arguments))
>>> c.execute_command = execute_cmd
>>> c.execute(hooke=None) # doctest: +ELLIPSIS
>>> c.execute_command(hooke=None, command_message=cm)
EXECUTE CommandC {'param': 'E'}
>>> c.append(cm)
- >>> print [repr(cm) for cm in c] # doctest: +NORMALIZE_WHITESPACE
+ >>> print([repr(cm) for cm in c]) # doctest: +NORMALIZE_WHITESPACE
['<CommandMessage CommandA {param: A}>',
'<CommandMessage CommandB {param: B}>',
'<CommandMessage CommandA {param: C}>',
>>> import pickle
>>> s = pickle.dumps(c)
>>> z = pickle.loads(s)
- >>> print '\\n'.join([repr(cm) for cm in c]
- ... ) # doctest: +NORMALIZE_WHITESPACE,
+ >>> print('\\n'.join([repr(cm) for cm in c]))
+ ... # doctest: +NORMALIZE_WHITESPACE
<CommandMessage CommandA {param: A}>
<CommandMessage CommandB {param: B}>
<CommandMessage CommandA {param: C}>
<CommandMessage CommandB {param: D}>,
<CommandMessage CommandC {param: E}>]}>
>>> import yaml
- >>> print yaml.dump(c) # doctest: +REPORT_UDIFF
+ >>> print(yaml.dump(c)) # doctest: +REPORT_UDIFF
!!python/object/new:hooke.command_stack.CommandStack
listitems:
- !!python/object:hooke.engine.CommandMessage
There is also a convenience function for clearing the stack.
>>> c.clear()
- >>> print [repr(cm) for cm in c]
+ >>> print([repr(cm) for cm in c])
[]
YAMLize a curve argument.
>>> from .curve import Curve
>>> c.append(CommandMessage('curve info', {'curve': Curve(path=None)}))
- >>> print yaml.dump(c) # doctest: +REPORT_UDIFF
+ >>> print(yaml.dump(c)) # doctest: +REPORT_UDIFF
!!python/object/new:hooke.command_stack.CommandStack
listitems:
- !!python/object:hooke.engine.CommandMessage
>>> c.append(CommandMessage('CommandB', {'param':'B'}))
>>> c.append(CommandMessage('CommandA', {'param':'C'}))
>>> c.append(CommandMessage('CommandB', {'param':'D'}))
- >>> print c.flatten()
+ >>> print(c.flatten())
- arguments: {param: A}
command: CommandA
- arguments: {param: B}
... '''
>>> c = FileCommandStack()
>>> c.from_string(string)
- >>> print [repr(cm) for cm in c] # doctest: +NORMALIZE_WHITESPACE
+ >>> print([repr(cm) for cm in c]) # doctest: +NORMALIZE_WHITESPACE
['<CommandMessage CommandA {param: A}>',
'<CommandMessage CommandB {param: B}>',
'<CommandMessage CommandA {param: C}>',
>>> import yaml
>>> s = yaml.dump(d)
- >>> print s
+ >>> print(s)
!hooke.curve.DataInfo
columns: [distance (m), force (N)]
<BLANKLINE>
[<CommandMessage curve info {curve: <Curve path>}>]
>>> z.command_stack[-1].arguments['curve'] == z
True
- >>> print yaml.dump(c) # doctest: +REPORT_UDIFF
+ >>> print(yaml.dump(c)) # doctest: +REPORT_UDIFF
&id001 !!python/object:hooke.curve.Curve
command_stack: !!python/object/new:hooke.command_stack.CommandStack
listitems:
YAML still works, though.
- >>> print yaml.dump(c.command_stack) # doctest: +REPORT_UDIFF
+ >>> print(yaml.dump(c.command_stack)) # doctest: +REPORT_UDIFF
&id001 !!python/object/new:hooke.command_stack.CommandStack
listitems:
- !!python/object:hooke.engine.CommandMessage
>>> sep = os.path.sep
>>> os.path.sep = '/'
- >>> print slash_join('abc', 'def/ghi', 'jkl\\mno')
+ >>> print(slash_join('abc', 'def/ghi', 'jkl\\mno'))
abc/def/ghi/jkl\mno
>>> os.path.sep = '\\'
- >>> print slash_join('abc', 'def/ghi', 'jkl\\mno')
+ >>> print(slash_join('abc', 'def/ghi', 'jkl\\mno'))
abc/def/ghi/jkl\mno
>>> os.path.sep = sep
self.filename=filename
self.othername=othername
- #print self.filename, self.othername
+ #print('{} {}'.format(self.filename, self.othername))
self.filedata=open(filename,'rb')
self.reddata=self.filedata.read()
def _time_from_localtime_string(self, timestring, format="%Y%m%d%H%M%S"):
"""
- >>> print time.tzname
+ >>> print(time.tzname)
('EST', 'EDT')
>>> d = WTKDriver()
>>> d._time_from_localtime_string("19700101", format="%Y%m%d")/3600.0
--------
>>> from .compat.odict import odict
>>> cm = CommandMessage('command A')
- >>> print unicode(cm)
+ >>> print(unicode(cm))
<CommandMessage command A>
>>> cm.arguments = odict([('param a','value a'), ('param b', 'value b')])
- >>> print unicode(cm)
+ >>> print(unicode(cm))
<CommandMessage command A {param a: value a, param b: value b}>
The parameters are sorted by name, so you won't be surprised
in any doctests, etc.
>>> cm.arguments = odict([('param b','value b'), ('param a', 'value a')])
- >>> print unicode(cm)
+ >>> print(unicode(cm))
<CommandMessage command A {param a: value a, param b: value b}>
"""
if len(self.arguments) > 0:
feed = multiprocessing.queues.Queue._feed
def new_feed (buffer, notempty, send, writelock, close):
def s(obj):
- print 'SEND:', obj, dir(obj)
+ print('SEND: {} {}'.format(obj, dir(obj)))
for a in dir(obj):
attr = getattr(obj, a)
- #print ' ', a, attr, type(attr)
+ #print(' {} {} {}'.format(a, attr, type(attr)))
if obj.__class__.__name__ == 'Hooke':
# Set suspect attributes to None until you resolve the
# PicklingError. Then fix whatever is breaking the
help="Enable debug logging.")
options,arguments = p.parse_args()
if len(arguments) > 0:
- print >> sys.stderr, 'More than 0 arguments to %s: %s' \
- % (sys.argv[0], arguments)
+ sys.stderr.write('More than 0 arguments to {}: {}\n'.format(
+ sys.argv[0], arguments))
p.print_help(sys.stderr)
sys.exit(1)
if options.config != None:
runner = HookeRunner()
if options.version == True:
- print version()
+ print(version())
sys.exit(0)
if options.debug == True:
hooke.config.set(
try:
self.__dict__.update(state)
except TypeError, e:
- print state, type(state), e
+ print(' '.join(str(x) for x in [state, type(state), e]))
if self.info in [None, {}]:
self.info = {}
Examples
--------
- >>> print playlist_path('playlist')
+ >>> print(playlist_path('playlist'))
playlist.hkp
- >>> print playlist_path('playlist.hkp')
+ >>> print(playlist_path('playlist.hkp'))
playlist.hkp
- >>> print playlist_path(None)
+ >>> print(playlist_path(None))
None
"""
if path == None:
>>> s = pickle.dumps(p)
>>> z = pickle.loads(s)
>>> for curve in z:
- ... print curve
+ ... print(curve)
<Curve A>
<Curve B>
- >>> print z.drivers
+ >>> print(z.drivers)
['Driver A', 'Driver B']
The data-type is also YAMLable (see :mod:`hooke.util.yaml`).
>>> s = yaml.dump(p)
>>> z = yaml.load(s)
>>> for curve in z:
- ... print curve
+ ... print(curve)
<Curve A>
<Curve B>
- >>> print z.drivers
+ >>> print(z.drivers)
['Driver A', 'Driver B']
"""
version = '0.2'
... CommandMessage('command B', {'arg 0':1, 'curve':c}),
... ])
>>> p.append_curve(c)
- >>> print p.flatten() # doctest: +REPORT_UDIFF
+ >>> print(p.flatten()) # doctest: +REPORT_UDIFF
# Hooke playlist version 0.2
!!python/object/new:hooke.playlist.FilePlaylist
listitems:
version: '0.2'
<BLANKLINE>
>>> p.relative_curve_paths = False
- >>> print p.flatten() # doctest: +REPORT_UDIFF
+ >>> print(p.flatten()) # doctest: +REPORT_UDIFF
# Hooke playlist version 0.2
!!python/object/new:hooke.playlist.FilePlaylist
listitems:
>>> p = from_string(string)
>>> p.set_path('/path/to/playlist')
>>> for curve in p:
- ... print curve.name, curve.path
+ ... print('{} {}'.format(curve.name, curve.path))
one /path/to/curve/one
two /path/to/curve/two
>>> p.info
{'note': 'An example playlist'}
>>> for curve in p:
- ... print curve.name, curve.path
+ ... print('{} {}'.format(curve.name, curve.path))
one /path/to/curve/one
two /path/to/curve/two
>>> p[-1].info['attr with spaces']
maxpoint=True
if rebase:
- print 'Select baseline'
+ print('Select baseline')
self.basepoints=self._measure_N_points(N=2, whatset=whatset)
self.basecurrent=self.current.path
if maxpoint:
- print 'Select two points'
+ print('Select two points')
points=self._measure_N_points(N=2, whatset=whatset)
boundpoints=[points[0].index, points[1].index]
boundpoints.sort()
try:
y=min(plot.vectors[whatset][1][boundpoints[0]:boundpoints[1]])
except ValueError:
- print 'Chosen interval not valid. Try picking it again. Did you pick the same point as begin and end of interval?'
+ print('Chosen interval not valid. Try picking it again. Did '
+ 'you pick the same point as begin and end of interval?')
else:
- print 'Select point to measure'
+ print('Select point to measure')
points=self._measure_N_points(N=1, whatset=whatset)
#whatplot=points[0].dest
y=points[0].graph_coords[1]
avg=np.mean(to_average)
forcebase=abs(y-avg)
- print str(forcebase*(10**12))+' pN'
+ print('{} pN'.format(forcebase * 10**12))
to_dump='forcebase '+self.current.path+' '+str(forcebase*(10**12))+' pN'
self.outlet.push(to_dump)
# Decides between the two forms of user input, as per (args)
if fitspan == 0:
# Gets the Xs of two clicked points as indexes on the current curve vector
- print 'Click twice to delimit chunk'
+ print('Click twice to delimit chunk')
points=self._measure_N_points(N=2,whatset=1)
else:
- print 'Click once on the leftmost point of the chunk (i.e.usually the peak)'
+ print('Click once on the leftmost point of the chunk (i.e.usually the peak)')
points=self._measure_N_points(N=1,whatset=1)
slope=self._slope(points,fitspan)
# Outputs the relevant slope parameter
- print 'Slope:'
- print str(slope)
+ print('Slope:')
+ print(str(slope))
to_dump='slope '+self.current.path+' '+str(slope)
self.outlet.push(to_dump)
try:
parameters=self.linefit_between(clickedpoints[0],clickedpoints[1])
except:
- print 'Cannot fit. Did you click twice the same point?'
+ print('Cannot fit. Did you click twice the same point?')
return
# Outputs the relevant slope parameter
- print 'Slope:'
- print str(parameters[0])
+ print('Slope:')
+ print(str(parameters[0]))
to_dump='slope '+self.curve.path+' '+str(parameters[0])
self.outlet.push(to_dump)
>>> outqueue = Queue()
>>> L,a = model.fit(outqueue=outqueue)
>>> fit_info = outqueue.get(block=False)
- >>> print L
+ >>> print(L)
3.5e-08
- >>> print a
+ >>> print(a)
2.5e-10
Fit the example data with a one-parameter fit (`L`). We introduce
>>> model = FJC(d_data, info=info, rescale=True)
>>> L, = model.fit(outqueue=outqueue)
>>> fit_info = outqueue.get(block=False)
- >>> print L # doctest: +ELLIPSIS
+ >>> print(L) # doctest: +ELLIPSIS
3.199...e-08
"""
def Lp(self, L):
>>> outqueue = Queue()
>>> N,a = model.fit(outqueue=outqueue)
>>> fit_info = outqueue.get(block=False)
- >>> print N
+ >>> print(N)
123.0
- >>> print a
+ >>> print(a)
7e-10
Fit the example data with a one-parameter fit (`N`). We introduce
>>> model = FJC_PEG(d_data, info=info, rescale=True)
>>> N, = model.fit(outqueue=outqueue)
>>> fit_info = outqueue.get(block=False)
- >>> print N # doctest: +ELLIPSIS
+ >>> print(N) # doctest: +ELLIPSIS
96.931...
"""
def Lr(self, L):
>>> outqueue = Queue()
>>> L,p = model.fit(outqueue=outqueue)
>>> fit_info = outqueue.get(block=False)
- >>> print L
+ >>> print(L)
3.5e-08
- >>> print p
+ >>> print(p)
2.5e-10
Fit the example data with a one-parameter fit (`L`). We introduce
>>> model = WLC(d_data, info=info, rescale=True)
>>> L, = model.fit(outqueue=outqueue)
>>> fit_info = outqueue.get(block=False)
- >>> print L # doctest: +ELLIPSIS
+ >>> print(L) # doctest: +ELLIPSIS
3.318...e-08
"""
def Lp(self, L):
self.Refresh()
def OnPaint(self, event):
- print 'painting'
+ print('painting')
super(PlotPanel, self).OnPaint(event)
self._c['canvas'].draw()
return (lipc, btn)
except:
import traceback
- print traceback.print_exc()
+ print(traceback.print_exc())
def UpdateControl(self, property, ctrl):
ctrl.SetValue(property.GetDisplayedString())
returned arguments of the method they're attached to.
>>> def c(self, method, *args):
- ... print '\\n '.join([
+ ... print('\\n '.join([
... 'callback:',
... 'class: %s' % self,
... 'method: %s' % method,
- ... 'returned: %s' % args])
+ ... 'returned: %s' % args]))
For some class, decorate any functions you're interested in
attaching callbacks too. Also, add a `_callbacks` attribute
... @callback
... def xyz(self):
... "xyz's docstring"
- ... print 'usual xyz business'
+ ... print('usual xyz business')
... return (0, 1, 1, 2, 3, 5)
...
... @callback
... def abc(self):
... "abc's docstring"
- ... print 'usual abc business'
+ ... print('usual abc business')
...
>>> x = X()
The decorated method preserves the original docstring.
- >>> print x.xyz.__doc__
+ >>> print(x.xyz.__doc__)
xyz's docstring
So far, we haven't attached a callback to `abc`.
array of callbacks in series.
>>> def d(self, method, *args):
- ... print 'callback d'
+ ... print('callback d')
>>> x._callbacks['abc'] = [d, c, d]
>>> r = x.abc() # doctest: +ELLIPSIS
usual abc business
returned arguments of the method they're attached to.
>>> def c(self, method, *args, **kwargs):
- ... print '\\n '.join([
+ ... print('\\n '.join([
... 'callback:',
... 'class: %s' % self,
... 'method: %s' % method,
... 'args: %s' % (args,),
- ... 'kwargs: %s' % kwargs])
+ ... 'kwargs: %s' % kwargs]))
Now place `in_callback` calls inside any interesting methods.
...
... def xyz(self):
... "xyz's docstring"
- ... print 'usual xyz business'
+ ... print('usual xyz business')
... in_callback(self, 5, my_kw=17)
... return (0, 1, 1, 2, 3, 5)
...
... def abc(self):
... "abc's docstring"
... in_callback(self, p1=3.14, p2=159)
- ... print 'usual abc business'
+ ... print('usual abc business')
...
>>> x = X()
array of callbacks in series.
>>> def d(self, method, *args, **kwargs):
- ... print 'callback d'
+ ... print('callback d')
>>> x._callbacks['abc'] = [d, c, d]
>>> r = x.abc() # doctest: +ELLIPSIS
callback d
>>> def x(depth):
... y(depth)
>>> def y(depth):
- ... print caller_name(depth)
+ ... print(caller_name(depth))
>>> x(1)
y
>>> x(2)
>>> def y():
... z()
>>> def z():
- ... print list(caller_names())
+ ... print(list(caller_names()))
>>> x() # doctest: +ELLIPSIS
['z', 'y', 'x', ...]
>>> y() # doctest: +ELLIPSIS
machine rounding during computation. We expect the values to be close
to the input settings (slope 7, offset -33).
- >>> print '%.3f' % slope
+ >>> print('{:.3f}'.format(slope))
7.000
- >>> print '%.3f' % offset
+ >>> print('{:.3f}'.format(offset))
-32.890
The offset is a bit off because, the range is not a multiple of
>>> m = LinearModel(data, rescale=True)
>>> outqueue = Queue()
>>> slope,offset = m.fit(outqueue=outqueue)
- >>> print '%.3f' % slope
+ >>> print('{:.3f}'.format(slope))
7.000
- >>> print '%.3f' % offset
+ >>> print('{:.3f}'.format(offset))
-32.890
Test single-parameter models:
>>> data = 20*numpy.sin(arange(1000)) + 7.*arange(1000)
>>> m = SingleParameterModel(data)
>>> slope, = m.fit(outqueue=outqueue)
- >>> print '%.3f' % slope
+ >>> print('{:.3f}'.format(slope))
7.000
"""
def __init__(self, *args, **kwargs):
# def dist(px,py,linex,liney):
# distancesx=scipy.array([(px-x)**2 for x in linex])
# minindex=numpy.argmin(distancesx)
-# print px, linex[0], linex[-1]
+# print(px, linex[0], linex[-1])
# return (py-liney[minindex])**2
#
#
We can list all of a node's ancestors.
- >>> print [node for node in d.ancestors()]
+ >>> print([node for node in d.ancestors()])
[b, c, a]
- >>> print [node for node in d.ancestors(depth_first=True)]
+ >>> print([node for node in d.ancestors(depth_first=True)])
[b, a, c]
Ancestors works with cycles.
>>> a.append(d)
- >>> print [node for node in d.ancestors()]
+ >>> print([node for node in d.ancestors()])
[b, c, a, d]
We can find the cycle path.
- >>> print d.parent_path(d)
+ >>> print(d.parent_path(d))
[b, a, d]
After a run through :meth:`Graph.set_children`, we can also
>>> g = Graph([a, b, c, d])
>>> g.set_children()
- >>> print a.children
+ >>> print(a.children)
[b, c]
And descendents.
- >>> print [node for node in a.descendents(depth_first=True)]
+ >>> print([node for node in a.descendents(depth_first=True)])
[b, d, a, c]
"""
def __init__(self, parents=[], data=None):
p = GraphRowPrinter(tip_to_root=tip_to_root)
for node in nodes:
g.insert(node)
- print p(g[-1])
+ print(p(g[-1]))
For the split/join branch columns, "born" and "dead" are defined
from the point of view of `GraphRow`. For root-to-tip ordering
>>> n.i.extend([n.f, n.g, n.h])
>>> g = Graph([n.a,n.b,n.c,n.d,n.e,n.f,n.g,n.h,n.i])
>>> g.topological_sort(tip_to_root=True)
- >>> print [node for node in g]
+ >>> print([node for node in g])
[i, h, g, f, e, d, c, b, a]
- >>> print g.ascii_graph()
+ >>> print(g.ascii_graph())
r-\-\ a
| | * b
| * | c
| * | g
* | | h
t-/-/ i
- >>> print g.ascii_graph(tip_to_root=True)
+ >>> print(g.ascii_graph(tip_to_root=True))
t-\-\ i
| | * h
| * | g
>>> n.g.extend([n.e, n.f])
>>> n.h.extend([n.c, n.g])
>>> g = Graph([n.a,n.b,n.c,n.d,n.e,n.f,n.g,n.h])
- >>> print g.ascii_graph(tip_to_root=True)
+ >>> print(g.ascii_graph(tip_to_root=True))
t-\ h
| *-\ g
| | *-\ f
... nx = getattr(n, char)
... n.i.append(nx)
>>> g = Graph([n.a,n.b,n.c,n.d,n.e,n.f,n.g,n.h,n.i])
- >>> print g.ascii_graph(tip_to_root=True)
+ >>> print(g.ascii_graph(tip_to_root=True))
t-\-\-\-\-\-\-\ i
| | | | | | | r h
| | | | | | r g
... nx = getattr(n, char)
... nx.append(n.a)
>>> g = Graph([n.a,n.b,n.c,n.d,n.e,n.f,n.g,n.h,n.i])
- >>> print g.ascii_graph(tip_to_root=True)
+ >>> print(g.ascii_graph(tip_to_root=True))
t i
| t h
| | t g
>>> n.h.extend([n.a, n.c, n.d, n.g])
>>> n.i.extend([n.a, n.b, n.c, n.g])
>>> g = Graph([n.a,n.b,n.c,n.d,n.e,n.f,n.g,n.h,n.i])
- >>> print g.ascii_graph(tip_to_root=True)
+ >>> print(g.ascii_graph(tip_to_root=True))
t-\-\-\ i
| | | | t-\-\-\ h
| | | *-|-|-|-<-\ g
... Peak(name='c', index=23, values=data[23:27]),
... Peak(name='d', index=100, values=data[100:101])]
>>> peaks = merge_double_peaks(data, peaks, see_double=10)
- >>> print '\\n'.join([str(p) for p in peaks])
+ >>> print('\\n'.join([str(p) for p in peaks]))
<Peak a 10:27>
<Peak d 100:101>
>>> min(peaks[0].values == data[10:27])
... Peak(name='c', index=23, values=data[23:27]),
... Peak(name='d', index=100, values=data[100:101])]
>>> peaks = drop_narrow_peaks(peaks, min_points=3)
- >>> print '\\n'.join([str(p) for p in peaks])
+ >>> print('\\n'.join([str(p) for p in peaks]))
<Peak b 15:18>
<Peak c 23:27>
"""
return inside
def print_postscript(sample, hull):
- print "%!"
- print "100 500 translate 2 2 scale 0 0 moveto"
- print "/tick {moveto 0 2 rlineto 0 -4 rlineto 0 2 rlineto"
- print " 2 0 rlineto -4 0 rlineto 2 0 rlineto} def"
+ print('%!')
+ print('100 500 translate 2 2 scale 0 0 moveto')
+ print('/tick {moveto 0 2 rlineto 0 -4 rlineto 0 2 rlineto')
+ print(' 2 0 rlineto -4 0 rlineto 2 0 rlineto} def')
for (x,y) in sample:
- print x, y, "tick"
- print "stroke"
- print hull[0,0], hull[0,1], "moveto"
+ print('{} {} tick'.format(x, y))
+ print('stroke')
+ print(hull[0,0], hull[0,1], 'moveto')
for (x,y) in hull[1:]:
- print x, y, "lineto"
- print "closepath stroke showpage"
+ print('{} {} lineto'.format(x, y))
+ print('closepath stroke showpage')
if __name__ == "__main__":
#sample = 10*array([(x,y) for x in arange(10) for y in arange(10)])
>>> p = get_power(xs[0])
>>> for x in xs:
-... print ppSI(x, decimals=2, power=p)
+... print(ppSI(x, decimals=2, power=p))
985.00 p
1000.00 p
112358.00 p
->>> print prefix_from_value(xs[0]) + 'N'
+>>> print(prefix_from_value(xs[0]) + 'N')
pN
"""
Examples
--------
>>> x = math.pi * 1e-8
- >>> print ppSI(x, 'N')
+ >>> print(ppSI(x, 'N'))
31.415927 nN
- >>> print ppSI(x, 'N', 3)
+ >>> print(ppSI(x, 'N', 3))
31.416 nN
- >>> print ppSI(x, 'N', 4, power=-12)
+ >>> print(ppSI(x, 'N', 4, power=-12))
31415.9265 pN
- >>> print ppSI(x, 'N', 5, pad=True)
+ >>> print(ppSI(x, 'N', 5, pad=True))
31.41593 nN
If you want the decimal indented by six spaces with `decimal=2`,
* 1 (length of the decimal point)
* 2 (places after the decimal point)
- >>> print ppSI(-x, 'N', 2, pad=(6+1+2))
+ >>> print(ppSI(-x, 'N', 2, pad=(6+1+2)))
-31.42 nN
"""
if value == 0:
>>> class A (Singleton):
... def init(self):
-... print 'initializing instance of %s at (%s)' % (
-... self.__class__.__name__, id(self))
+... print('initializing instance of {} at ({})'.format(
+... self.__class__.__name__, id(self)))
>>> A_instances = [A() for i in range(3)] # doctest: +ELLIPSIS
initializing instance of A at (...)
>>> for i in A_instances[1:]:
-... print id(i) == id(A_instances[0])
+... print(id(i) == id(A_instances[0]))
True
True
>>> B_instances = [B() for i in range(3)] # doctest: +ELLIPSIS
initializing instance of B at (...)
>>> for i in B_instances[1:]:
-... print id(i) == id(B_instances[0])
+... print(id(i) == id(B_instances[0]))
True
True
>>> id(A_instances[0]) == id(B_instances[0])
>>> import yaml
>>> a = numpy.array([1,2,3])
->>> print yaml.dump(a)
+>>> print(yaml.dump(a))
null
...
<BLANKLINE>
>>> yaml.Dumper.yaml_representers.pop(numpy.ndarray) # doctest: +ELLIPSIS
<function none_representer at 0x...>
->>> print yaml.dump(a) # doctest: +REPORT_UDIFF
+>>> print(yaml.dump(a)) # doctest: +REPORT_UDIFF
!!python/object/apply:numpy.core.multiarray._reconstruct
args:
- !!python/name:numpy.ndarray ''
define new types (e.g. numpy.ndarray) which YAML cannot inspect.
"""
def ignore_aliases(data):
- print data, repr(data), type(data), repr(type(data))
+ print(' '.join(str(x) for x in [
+ data, repr(data), type(data), repr(type(data))]))
sys.stdout.flush()
if data in [None, ()]:
return True
engine message from apply command stack to playlist
(<class 'hooke.command.Success'>):
>>> for c in curve.command_stack:
-... print c # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
+... print(c) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
<CommandMessage zero surface contact point
{..., curve: <Curve 20071120a_i27_t33.100>...}>
<CommandMessage flat filter peaks {block: retract, min points: 1}>
... text = f.read()
>>> if block_info_already_exists == False:
... os.remove(file_name)
->>> print text # doctest: +ELLIPSIS, +REPORT_UDIFF
+>>> print(text) # doctest: +ELLIPSIS, +REPORT_UDIFF
picoforce.000:
approach:
columns: [z piezo (m), deflection (m)]
>>> os.listdir(target_dir)
['default']
>>> with open(os.path.join(target_dir, 'default'), 'r') as f:
-... print f.read()
+... print(f.read())
- arguments: {input: test/data/test}
command: load playlist
- arguments: {}
>>> sorted(os.listdir(target_dir))
['default', 'my_stack']
>>> with open(os.path.join(target_dir, 'my_stack'), 'r') as f:
-... print f.read()
+... print(f.read())
- arguments: {input: test/data/test}
command: load playlist
- arguments: {}
Success
<BLANKLINE>
>>> with open(os.path.join(target_dir, 'default'), 'r') as f:
-... print f.read()
+... print(f.read())
- arguments: {input: test/data/test}
command: load playlist
- arguments: {}
command: get curve
<BLANKLINE>
>>> with open(os.path.join(target_dir, 'my_stack'), 'r') as f:
-... print f.read()
+... print(f.read())
- arguments: {input: test/data/test}
command: load playlist
- arguments: {}
Success
<BLANKLINE>
>>> with open(os.path.join(target_dir, 'default'), 'r') as f:
-... print f.read()
+... print(f.read())
- arguments: {}
command: version
<BLANKLINE>
... lines = f.readlines()
>>> if export_already_exists == False:
... os.remove(file_name)
->>> print len(lines)
+>>> len(lines)
2049
->>> print ''.join(lines[:5]), # doctest: +ELLIPSIS, +REPORT_UDIFF +NORMALIZE_WHITESPACE
+>>> print(''.join(lines[:5]).rstrip())
+... # doctest: +ELLIPSIS, +REPORT_UDIFF +NORMALIZE_WHITESPACE
# z piezo (m) deflection (m)
-1.519...e-07 9.094...e-08
-1.513...e-07 9.130...e-08
>>> p = h.playlists.current()
>>> for i,curve in enumerate(p.items()):
-... print (i,
+... print((i,
... curve.info['raw info']['file-format-version'],
-... [d.info['name'] for d in curve.data]) # doctest: +REPORT_UDIFF
+... [d.info['name'] for d in curve.data])) # doctest: +REPORT_UDIFF
(0, '0.5', ['approach', 'retract'])
(1, '0.5', ['approach', 'pause', 'retract'])
(2, '0.2', ['pause-0', 'approach', 'pause-1', 'retract'])
>>> base_dir = os.path.join('test', 'data', 'vclamp_jpk', 'Data1D')
>>> for file_name in sorted(os.listdir(base_dir)):
... path = os.path.join(base_dir, file_name)
-... print path
-... print driver.is_me(path)
+... print(path)
+... print(driver.is_me(path))
... data = driver.read(path)
-... print data.shape, data[:5], data[-5:]
+... print(' '.join(str(x) for x in [data.shape, data[:5], data[-5:]]))
... # doctest: +ELLIPSIS, +REPORT_UDIFF
test/data/vclamp_jpk/Data1D/data1D-ConstantData1D-1282315524304.jpk-data1D
True
>>> curve
<Curve 20071120a_i27_t33.100>
>>> for c in curve.command_stack:
-... print c # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
+... print(c) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
<CommandMessage zero surface contact point {block: retract}>
<CommandMessage flat filter peaks {block: retract, min points: 1}>
<CommandMessage zero surface contact point {block: retract, ignore after last peak info name: flat filter peaks}>
<CommandMessage flat peaks to polymer peaks {block: retract}>
<CommandMessage polymer fit peaks {block: retract}>
>>> for c in curve.data[-1].info['columns']:
-... print c # doctest: +REPORT_UDIFF
+... print(c) # doctest: +REPORT_UDIFF
z piezo (m)
deflection (m)
surface distance (m)
>>> curve
<Curve 20071120a_i27_t33.101>
>>> for c in curve.command_stack:
-... print c # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
+... print(c) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
<CommandMessage zero surface contact point {block: retract}>
<CommandMessage flat filter peaks {block: retract, min points: 1}>
<CommandMessage zero surface contact point {block: retract, ignore after last peak info name: flat filter peaks}>
<CommandMessage flat peaks to polymer peaks {block: retract}>
<CommandMessage polymer fit peaks {block: retract}>
>>> for c in curve.data[-1].info['columns']:
-... print c # doctest: +REPORT_UDIFF
+... print(c) # doctest: +REPORT_UDIFF
z piezo (m)
deflection (m)
surface distance (m)