Programming with Sage: defining module

i like this post (click again to cancel)
1
i dont like this post (click again to cancel)

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.

asked Dec 21 '11

Nicolas Essis-Breton gravatar image Nicolas Essis-Breton
37 6

updated Dec 21 '11

Shashank gravatar image Shashank flag of United States
1570 5 22 55
i like this answer (click again to cancel)
3
i dont like this answer (click again to cancel) Nicolas Essis-Breton has selected this answer as correct

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')
link

posted Dec 21 '11

Shashank gravatar image Shashank flag of United States
1570 5 22 55

@Shashank Thanks Shashank.

Nicolas Essis-Breton (Dec 21 '11)

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Tags:

Stats:

Asked: Dec 21 '11

Seen: 81 times

Last updated: Dec 21 '11

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.