Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
print to python3 format in interact
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Chapoton committed Apr 29, 2016
1 parent c04fdff commit 0f38d3f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
17 changes: 9 additions & 8 deletions src/sage/interacts/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- William Stein (2012)
"""
from __future__ import print_function
# Below all tests are done using sage0, which is a pexpect interface
# to Sage itself. This allows us to test exploring a stack traceback
# using the doctest framework.
Expand Down Expand Up @@ -116,8 +117,8 @@ def evaluate(self, line):
sage: _ = sage0.eval("sage.interacts.debugger.test_function('n', 'm')")
sage: _ = sage0.eval('d = sage.interacts.debugger.Debug()')
sage: sage0.eval("d.evaluate('print a, b')")
'm n'
sage: sage0.eval("d.evaluate('print(a);print(b)')")
'm\nn'
"""
locals = self.curframe().f_locals
globals = self.curframe().f_globals
Expand All @@ -131,7 +132,7 @@ def evaluate(self, line):
exc_type_name = t
else:
exc_type_name = t.__name__
print '***', exc_type_name + ':', v
print('*** {}: {}'.format(exc_type_name, v))

def listing(self, n=5):
"""
Expand All @@ -151,20 +152,20 @@ def listing(self, n=5):
sage: _ = sage0.eval("sage.interacts.debugger.test_function('n', 'm')")
sage: _ = sage0.eval('d = sage.interacts.debugger.Debug()')
sage: print sage0("d.listing(1)")
sage: print(sage0("d.listing(1)"))
2... x = a + b
--> ... y = a * b
... return x, y, x<y, x>y # < to ensure HTML is properly escaped
<hr>> <a href="/src/interacts/debugger.py" target="_new">src/sage/interacts/debugger.py</a>
sage: print sage0("d.listing()")
sage: print(sage0("d.listing()"))
2...
...
... x = a + b
--&gt; ... y = a * b
... return x, y, x&lt;y, x&gt;y # &lt; to ensure HTML is properly escaped
...
sage: _ = sage0.eval('d._curframe_index -= 1')
sage: print sage0("d.listing(1)")
sage: print(sage0("d.listing(1)"))
4... else:
--&gt; ... test_function2(m, n)
...
Expand Down Expand Up @@ -253,7 +254,7 @@ def dbg(frame = slider(vmin=0, vmax=len(self._stack)-1, step_size=1, default=len
# must have hit the evaluate button
self.evaluate(command)

print '<html><hr>' + self.listing(lines//2) + '</html>'
print('<html><hr>{}</html>'.format(self.listing(lines//2)))
# save control state for next time around
self._last = {'command':command, 'button':button, 'lines':lines, 'frame':frame}

Expand Down Expand Up @@ -285,7 +286,7 @@ def debug():
from sage.plot.plot import EMBEDDED_MODE
if not EMBEDDED_MODE:
# Must be the command line, so suggest using the IPython debugger.
print "You should use %debug on the command line."
print("You should use %debug on the command line.")
else:
# Create the Debug object and make it interactive.
Debug().interact()
20 changes: 10 additions & 10 deletions src/sage/interacts/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def library_interact(f):
sage: import sage.interacts.library as library
sage: @library.library_interact
... def f(n=5): print n
...
....: def f(n=5): print(n)
....:
sage: f() # an interact appears, if using the notebook, else code
<html>...</html>
"""
Expand Down Expand Up @@ -80,7 +80,7 @@ def demo(n=tuple(range(10)), m=tuple(range(10))):
sage: interacts.demo()
<html>...</html>
"""
print n+m
print(n + m)

@library_interact
def taylor_polynomial(
Expand Down Expand Up @@ -765,7 +765,7 @@ def _bisection_method(f, a, b, maxn, eps):
try:
c, intervals = _bisection_method(f, float(a), float(b), maxn, h)
except ValueError:
print "f must have opposite sign at the endpoints of the interval"
print("f must have opposite sign at the endpoints of the interval")
show(plot(f, a, b, color='red'), xmin=a, xmax=b)
else:
html(r"$\text{Precision }h = 10^{-d}=10^{-%s}=%.5f$"%(d, float(h)))
Expand Down Expand Up @@ -825,7 +825,7 @@ def _secant_method(f, a, b, maxn, h):
a, b = interval
h = 10**(-d)
if float(f(a)*f(b)) > 0:
print "f must have opposite sign at the endpoints of the interval"
print("f must have opposite sign at the endpoints of the interval")
show(plot(f, a, b, color='red'), xmin=a, xmax=b)
else:
c, intervals = _secant_method(f, float(a), float(b), maxn, h)
Expand Down Expand Up @@ -1252,8 +1252,8 @@ def function_tool(f=sin(x), g=cos(x), xrange=range_slider(-3,3,default=(0,1),lab
try:
f = SR(f); g = SR(g); a = SR(a)
except TypeError as msg:
print msg[-200:]
print "Unable to make sense of f,g, or a as symbolic expressions in single variable x."
print(msg[-200:])
print("Unable to make sense of f,g, or a as symbolic expressions in single variable x.")
return
if not (isinstance(xrange, tuple) and len(xrange) == 2):
xrange = (0,1)
Expand Down Expand Up @@ -1514,13 +1514,13 @@ def polar_prime_spiral(
from sage.plot.colors import hue

if start < 1 or end <= start:
print "invalid start or end value"
print("invalid start or end value")
return
if n > end:
print "WARNING: n is greater than end value"
print("WARNING: n is greater than end value")
return
if n < start:
print "n < start value"
print("n < start value")
return
nn = SR.var('nn')
f1 = fast_float(sqrt(nn)*cos(2*pi*sqrt(nn)), 'nn')
Expand Down
19 changes: 10 additions & 9 deletions src/sage/interacts/library_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ AUTHORS:
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
from __future__ import print_function

from sage.misc.all import prod

Expand All @@ -25,9 +26,9 @@ cpdef julia(ff_j, z, int iterations):
INPUT:
- `ff_j` -- fast callable for the inner iteration
- `z` -- complex number
- `iterations` -- number of loops
- `ff_j` -- fast callable for the inner iteration
- `z` -- complex number
- `iterations` -- number of loops
TESTS::
Expand All @@ -50,9 +51,9 @@ cpdef mandel(ff_m, z, int iterations):
INPUT:
- `ff_m` -- fast callable for the inner iteration
- `z` -- complex number
- `iterations` -- number of loops
- `ff_m` -- fast callable for the inner iteration
- `z` -- complex number
- `iterations` -- number of loops
TESTS::
Expand Down Expand Up @@ -80,15 +81,15 @@ cpdef cellular(rule, int N):
INPUT:
- `rule` -- determines how a cell's value is updated, depending on its neighbors
- `N` -- number of iterations
- `rule` -- determines how a cell's value is updated, depending on its neighbors
- `N` -- number of iterations
TESTS::
sage: from sage.interacts.library_cython import cellular
sage: rule = [1, 0, 1, 0, 0, 1, 1, 0]
sage: N = 3
sage: print cellular(rule, N)
sage: print(cellular(rule, N))
[[0 0 0 1 0 0 0 0]
[1 1 0 1 0 1 0 0]
[0 1 1 1 1 1 0 0]]
Expand Down

0 comments on commit 0f38d3f

Please sign in to comment.