ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 25 Jun 2019 12:27:38 -0500Creating a module in Sagehttp://ask.sagemath.org/question/46994/creating-a-module-in-sage/I am new to Sage, being used to Python and I am having some trouble with adapting.
In particular, I am trying to create a 'module' in the Python sense, i.e. some set of classes that I can call with 'import'.
When I did this in python in the past, I would create a directory (say /my_module/ in my home) and include a file __'__init____.sage' in that file with a line
__all__ = ['Submodule1', 'Submodule2']
Then I would have a file 'Submodule1' and 'Submodule2'.
In the file 'Submodule 1' I would define 'Class1'
and then from a file 'run.py' in home I would write
import my_module
from my_module.Submodule1 import Class1
and then I would be able to write
c=Class1()
to create an object.
I find that this is not working in Sage and the only thing I seem to be able to do is write in run.py
load("my_module/Submodule1.sage")
for each class I want to load. This has many disadvantages, for instance hiding classes from potential users so that they only exist internally.
Any suggestions on how to create and import modules in sage? What is the sage way?
Jesus Martinez GarciaTue, 25 Jun 2019 12:27:38 -0500http://ask.sagemath.org/question/46994/