Ask Your Question

Revision history [back]

Use sage objects in python module files

Hello,

I'm trying to figure out how to use sage functions/classes in a module .py file, from another python file. Here's the thing, I'm developing a small simulator in Python 2 intended to be use with sage for solving diff. equations, etc... So I have different .py files (interface, calcul, etc) in which have been written some code using sage functions.

Let's say I have "y = var('y')" in calcul.py and I run it from sage console ->

sage: load("calcul.py") sage:

All works properly without any failures. But, if I want to import this module in interface.py and then run the file with sage, I get this error ->

sage: load("interface.py") ---> 1 y = var('y')

NameError: name 'var' is not defined

As if it didn't recognize its own functions. Is there any command/function to use in sage to allow loading of imported files without that type of error ?

Thanks in advance for your help.

Use sage objects in python module files

Hello,

I'm trying to figure out how to use sage functions/classes in a module .py file, from another python file. Here's the thing, I'm developing a small simulator in Python 2 intended to be use with sage for solving diff. equations, etc... So I have different .py files (interface, calcul, etc) in which have been written some code using sage functions.

Let's say I have "y = var('y')" in calcul.py and I run it from sage console ->

sage: load("calcul.py") sage:

All works properly without any failures. But, if I want to import this module in interface.py and then run the file with sage, I get this error ->

sage: load("interface.py") ---> 1 y = var('y')

NameError: name 'var' is not defined

As if it didn't recognize its own functions. Is there any command/function to use in sage to allow loading of imported files without that type of error ?

Thanks in advance for your help.