Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Programming with Sage: defining module

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.

Programming with Sage: defining module

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

'result.sage' file:
from addition import add add
print add(1,2) 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.

click to hide/show revision 3
retagged

Programming with Sage: defining module

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.