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:

  • http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/
  • http://ask.sagemath.org/question/33954/can-i-create-a-sage-file-and-import-it-as-a-python-module/