# Programming with Sage: defining module

 1 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 37 ● 6 Shashank 1570 ● 5 ● 22 ● 55

 3 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')  posted Dec 21 '11 Shashank 1570 ● 5 ● 22 ● 55 @Shashank Thanks Shashank.Nicolas Essis-Breton (Dec 21 '11)

[hide preview]

## Stats:

Asked: Dec 21 '11

Seen: 81 times

Last updated: Dec 21 '11