Ask Your Question

Programming with Sage: defining module

asked 2011-12-21 15:52:47 +0200

Nicolas Essis-Breton gravatar image

updated 2011-12-21 16:44:24 +0200

Shashank gravatar image

Let's say I want to write two modules 'addition.sage' and 'result.sage'.
I would like to import 'addition.sage' in 'result.sage'. How can I do this?
I've try the following, but it doesn't seem to work.

'addition.sage' file:
from sage.all import *

'result.sage' file:
from addition import add
print add(1,2)

my sage session:
sage: load('myPath/result.sage')

This gives me the error 'ImportError: No module named addition'.
Although, my PYTHONPATH contains the directory where my two modules are located.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-12-21 16:28:02 +0200

Shashank gravatar image

If result.sage is calling add function from addition.sage, you need to load that file in result.sage.

You can also load the file without giving the path, if you type the following two lines in the beginning of the notebook

import sys
edit flag offensive delete link more


@Shashank Thanks Shashank.

Nicolas Essis-Breton gravatar imageNicolas Essis-Breton ( 2011-12-21 20:18:47 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-12-21 15:52:47 +0200

Seen: 455 times

Last updated: Dec 21 '11