Ask Your Question
1

Programming with Sage: defining module

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

Nicolas Essis-Breton gravatar image

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

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 *
add(x,y)=x+y

'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
3

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

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
sys.path.append('path-to-module')
edit flag offensive delete link more

Comments

@Shashank Thanks Shashank.

Nicolas Essis-Breton gravatar imageNicolas Essis-Breton ( 2011-12-21 20:18:47 +0100 )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

Stats

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

Seen: 545 times

Last updated: Dec 21 '11