Ask Your Question

Revision history [back]

You are using Sage-specific syntax f(t) = t**n.

In a .py file, you cannot do that.

You have to replace it with pure Python-compliant code.

To understand what code you need to use, do this:

sage: preparse('f(t) = t**n')
'__tmp__=var("t"); f = symbolic_expression(t**n).function(t)'

Now you know how to write your function:

def my_func(n):
    t = SR.var('t')
    f = symbolic_expression(t**n).function(t)
    return f(t)

See also these related Ask Sage questions: