Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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)?