ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 05 Mar 2013 21:21:49 +0100Using timeit in an interact without string formattinghttps://ask.sagemath.org/question/9883/using-timeit-in-an-interact-without-string-formatting/I wanted the following to work, but it didn't. Anyone have an idea how to make it do so?
def T(n):
top = ceil(math.sqrt(n))
print top
@interact
def _(n=6739815371):
T(n)
timeit('T(n)')
Instead I had to do
def T(n):
top = ceil(math.sqrt(n))
print top
@interact
def _(n=6739815371):
T(n)
timeit('T(%s)'%n)
But I feel like the first thing did indeed work in the past (though I tried it with a Sage from 2010 to no avail).
I guess in some sense this is a silly question - `'T(n)'` is a string, pure and simple. At the same time, in the command line
sage: def T(n):
....: top = ceil(math.sqrt(n))
....: print top
....:
sage: n=6739815371
sage: timeit('T(n)')
625 loops, best of 3: 5.96 µs per loop
and `'T(n)'` is a string there too. So what is different about `interact` that this doesn't work (in Sage or the cell server)?kcrismanTue, 05 Mar 2013 21:21:49 +0100https://ask.sagemath.org/question/9883/